java + XML + dom4j

D

dat

Hi,
I have an XML file like this:

articleSet

article
title
/title
author
/author
/article

article
title
/title
author
/author
/article

/articleSet

using dom4j I put this XML into a org.dom4j.Document (named xmlDoc) and
for each "article" Node I wuold like to do some stuff so I wrote this code

Iterator iter = xmlDoc.selectNodes("//article").iterator();
while(iter.hasNext()){
Node n = (Node)iter.next();
System.out.println(n.asXML());
System.out.println(n.selectSingleNode("//title").getText());
}

the problem is that the first "println" prints correctly the content of
each "article" Node but the second prints always the FIRST article title
because the XPath search is done on entire document and not only inside
the current node.
Why this behaviour? I made some mistakes?
dat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top