[jdom-interest] Filter Content with xml:lang
Per Norrman
per.norrman at austers.se
Mon Mar 21 12:55:50 PST 2005
Hi,
not knowing why you want to do what you do, but bear in mind
that the xml:lang attribute behaves quite like an unprefixed
namespace declaration, i.e. child element and content inherits
the value.
<A xml:lang="se">
<B>det svenska folkets urgamla rätt att sig självt beskatta</B>
<A>
<A xml:lang="se">
<B xml:lang="">det svenska folkets urgamla rätt att sig självt beskatta</B>
<A>
The first B is in scope for xml:lang="se", while the second B has no
language information attached.
But maybe you already knew this.
/pmn
Sinkinson,Andrew [NCR] skrev:
> 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());
> }
> }
> }
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list