Hi all,
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.
Sample xml:
<Metadata xmlns="http://www.sampleNS.com">
<RecordInfo>
<Format xml:lang="en">StringEN</commonFormat>
<Format xml:lang="fr">StringFR</commonFormat>
<Format xml:lang="en">StringEN</commonFormat>
<Format xml:lang="fr">StringFR</commonFormat>
<commonFormatID>4</commonFormatID>
<test>
<subtest>222</subtest>
</test>
</RecordInfo>
</Metadata>
Here is the code that is almost working accept that I when I get the value of the root element and RecordInfo it give me all the content.
Any help would be greatly appreciated. Thanks
String[] sLang = {"en","fr"};
for (int t = 0; t < sLang.length; t++) {
Iterator itr = doc.getDescendants(new ElementFilter(myNS));
while (itr.hasNext()) {
Element oTemp = (Element) itr.next();
if(oTemp.getAttribute("lang",xmlNS) != null){
String attr = oTemp.getAttribute("lang",xmlNS).getValue();
if(attr.equalsIgnoreCase(sLang[t])){
System.out.println(oTemp.getValue());
}
}
else
{
System.out.println(oTemp.getValue());
}
}
}