java + XML + dom4j

Discussion in 'Java' started by dat, Oct 16, 2007.

  1. dat

    dat Guest

    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
     
    dat, Oct 16, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wolfgang
    Replies:
    0
    Views:
    704
    Wolfgang
    Jul 9, 2003
  2. Stefan Siegl
    Replies:
    2
    Views:
    777
    David Zimmerman
    Jul 17, 2003
  3. Cram TeXeD
    Replies:
    1
    Views:
    377
    Cram TeXeD
    Feb 2, 2004
  4. Timo Nentwig
    Replies:
    0
    Views:
    887
    Timo Nentwig
    Feb 4, 2004
  5. al schmid
    Replies:
    2
    Views:
    635
    al schmid
    Apr 10, 2005
Loading...

Share This Page