[jdom-interest] Filter Content with xml:lang
Sinkinson,Andrew [NCR]
Andrew.Sinkinson at ec.gc.ca
Mon Mar 21 12:15:56 PST 2005
After futher reviewing the Javadocs , I was using getValue() instead of
using getTextTrim(). The getValue returns "all text node descendants
of this element".
Thanks
-----Original Message-----
From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Sinkinson,Andrew
[NCR]
Sent: March 21, 2005 2:23 PM
To: jdom-interest at jdom.org
Subject: RE: [jdom-interest] Filter Content with xml:lang
Here is the correct Sample XML:
Sample xml:
<Metadata xmlns="http://www.sampleNS.com
<http://www.samplens.com/> ">
<RecordInfo>
<Format xml:lang="en">StringEN</Format>
<Format xml:lang="fr">StringFR</Format>
<Format xml:lang="en">StringEN</Format>
<Format xml:lang="fr">StringFR</Format>
<FormatID>4</FormatID>
<test>
<subtest>222</subtest>
</test>
</RecordInfo>
</Metadata>
-----Original Message-----
From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Sinkinson,Andrew
[NCR]
Sent: March 21, 2005 1:28 PM
To: jdom-interest at jdom.org
Subject: [jdom-interest] Filter Content with xml:lang
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());
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20050321/c3acee09/attachment.htm
More information about the jdom-interest
mailing list