<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6603.0">
<TITLE>Filter Content with xml:lang</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<BR>
<P><FONT SIZE=2 FACE="Arial"> Hi all,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial"> I am wondering what is the best way to filter out the content of a complex document based on xml:lang. Basically for each language I want to filter out all elements that match given xml:lang attribute and those that do not have an xml:lang attribute.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">Sample xml:</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">Metadata</FONT><FONT COLOR="#FF0000" SIZE=2 FACE="Arial"> xmlns</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">="</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial"><A HREF="http://www.sampleNS.com">http://www.sampleNS.com</A></FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">"></FONT>
<BR> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">RecordInfo</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">Format</FONT><FONT COLOR="#FF0000" SIZE=2 FACE="Arial"> xml:lang</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">="</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">en</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">"></FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">StringEN</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">commonFormat</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">Format</FONT><FONT COLOR="#FF0000" SIZE=2 FACE="Arial"> xml:lang</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">="</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">fr</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">"></FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">StringFR</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">commonFormat</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> <</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">Format</FONT><FONT COLOR="#FF0000" SIZE=2 FACE="Arial"> xml:lang</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">="</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">en</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">"></FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">StringEN</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">commonFormat</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">Format</FONT><FONT COLOR="#FF0000" SIZE=2 FACE="Arial"> xml:lang</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">="</FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">fr</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">"></FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">StringFR</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">commonFormat</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">commonFormatID</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">4</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">commonFormatID</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"><</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">test</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> <</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">subtest</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT><FONT COLOR="#000000" SIZE=2 FACE="Arial">222</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">subtest</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> </</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">test</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR> <FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">RecordInfo</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"></</FONT><FONT COLOR="#800000" SIZE=2 FACE="Arial">Metadata</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">></FONT>
</P>
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Here is the code that is almost working accept that I when I get the value of the root element and</FONT> <FONT COLOR="#800000" SIZE=2 FACE="Arial">RecordInfo</FONT><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> it give me all the content.</FONT></P>
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Any help would be greatly appreciated. Thanks</FONT>
</P>
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> String[] sLang = {"en","fr"};</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> for (int t = 0; t < sLang.length; t++) {</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> Iterator itr = doc.getDescendants(new ElementFilter(myNS));</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> while (itr.hasNext()) {</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> </FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> Element oTemp = (Element) itr.next();</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> </FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> if(oTemp.getAttribute("lang",xmlNS) != null){</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> String attr = oTemp.getAttribute("lang",xmlNS).getValue();</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> </FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> if(attr.equalsIgnoreCase(sLang[t])){</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> System.out.println(oTemp.getValue());</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> else</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> {</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> System.out.println(oTemp.getValue());</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> }</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial"> }</FONT>
</P>
</BODY>
</HTML>