xerces-j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arthur De Magalhaes <arthu...@ca.ibm.com>
Subject Re: Restrict getElementsByTagName to Top Level
Date Fri, 07 Aug 2009 01:46:07 GMT
Hi,

You could use namespaces to distinguish the two links, and then use the 
namespace variant of that method:  getElementsByTagNameNS [1].

So you could have something like:

<rootNode>
    <a:link xmlns:a="http://rootlink/">http://rootlink/</a:link>
    <image>
        <b:link xmlns:b="http://imagelink/">http://imagelink/</b:link>
        <title>This is the title</title>
    </image>
</rootNode>


Then use:  getElementsByTagNameNS("http://rootlink/", "link")

Thx,

[1] 
http://java.sun.com/j2se/1.4.2/docs/api/org/w3c/dom/Element.html#getElementsByTagNameNS(java.lang.String,%20java.lang.String)

Arthur De Magalhaes
Software Engineer - XML Parser & XCI Development
IBM Canada - Toronto Lab
Phone: 905-413-2993 T/L 313-2993
E-mail: arthurdm@ca.ibm.com




SGSWeb <sgsweb@websulting.com> 
08/06/2009 05:55 PM
Please respond to
j-dev@xerces.apache.org


To
j-dev@xerces.apache.org
cc

Subject
Restrict getElementsByTagName to Top Level






I have an XML file as follows:
<rootNode>
    <link>http://rootlink/</link>
    <image>
        <link>http://imagelink/</link>
        <title>This is the title</title>
    </image>
</rootNode>

The XML Java code using DOM is as follows:
NodeList rootNodeList = element.getElementsByTagName("link");

This will give me all of the "link" elements including the top level and 
the one inside the "image" node.
Is there a way to just get the "link" tags for rootNode within one level 
and not two such as is the case for the image link? That is, I just want 
the http://rootlink/ "link".
thanks,
sgs.

Mime
View raw message