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: [email protected]
SGSWeb <[email protected]>
08/06/2009 05:55 PM
Please respond to
[email protected]
To
[email protected]
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.