Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java + XML + dom4j

Reply
Thread Tools

java + XML + dom4j

 
 
dat
Guest
Posts: n/a
 
      10-16-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Continuously reading a result XML with dom4j al schmid Java 2 04-10-2005 09:37 AM
[dom4j] node.detach() -> NullPointerException Timo Nentwig Java 0 02-04-2004 11:35 AM
[Dom4j][Rules] What's wromng with this ? Cram TeXeD Java 1 02-02-2004 09:19 PM
[dom4j & Xerces] How to show validation errors? Stefan Siegl Java 2 07-17-2003 12:26 PM
How to compare to dom4j-Documents or How to read line by line from a dom4j-Document into a String? Wolfgang Java 0 07-09-2003 09:43 AM



Advertisments