Which function do I use to retrieve a whole hierarchy?

Discussion in 'XML' started by Scott Simpson, May 9, 2005.

  1. I can build portions of DOM trees with jdom and xpathapi and using "new
    Element()" and "appendChild()" or "addContent()". Which function do I
    use to get a whole portion of a DOM tree though? For example, suppose I have

    <foo>
    <bar name="dopey">
    <snafu>
    Text
    </snafu>
    </bar>
    <bar name="sleepy">
    <snafu>
    More text
    </snafu>
    </bar>
    </foo>

    I can use an XPath query like
    "/foo/bar[@name="dopey"]/ancestor-or-self::*" but that will give me back
    a *list* of all the nodes it found. I want a pointer to the top <bar>
    node and I want the rest of the stuff to be in a hierarchy below that
    just like it is in the XML file. Is there a way to retrieve a hierarchy?
    Thank you.
     
    Scott Simpson, May 9, 2005
    #1
    1. Advertising

  2. Scott Simpson <> writes:

    > I can build portions of DOM trees with jdom and xpathapi and using "new
    > Element()" and "appendChild()" or "addContent()". Which function do I
    > use to get a whole portion of a DOM tree though? For example, suppose I have
    >
    > <foo>
    > <bar name="dopey">
    > <snafu>
    > Text
    > </snafu>
    > </bar>
    > <bar name="sleepy">
    > <snafu>
    > More text
    > </snafu>
    > </bar>
    > </foo>
    >
    > I can use an XPath query like
    > "/foo/bar[@name="dopey"]/ancestor-or-self::*" but that will give me back
    > a *list* of all the nodes it found. I want a pointer to the top <bar>
    > node and I want the rest of the stuff to be in a hierarchy below that
    > just like it is in the XML file. Is there a way to retrieve a hierarchy?
    > Thank you.


    The Xpath to the top of the document is / which returns the root node
    (document node)

    I'm not sure what you mean by teh "top <bar> node as there are several
    sibling bar nodes in your example.
    /foo would return teh top level element
    /foo/bar[1] would return the first of the bar nodes.

    Once you have the node returned you can traverse the hierarchy below
    that point using dom cals in your application or further Xpaths or
    whatever.

    David
     
    David Carlisle, May 9, 2005
    #2
    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. Joel
    Replies:
    4
    Views:
    9,277
    John Harrison
    Oct 11, 2004
  2. \A_Michigan_User\
    Replies:
    2
    Views:
    913
    \A_Michigan_User\
    Aug 21, 2006
  3. Replies:
    13
    Views:
    1,661
    Roedy Green
    Aug 18, 2007
  4. Beauregard T. Shagnasty

    Re: Which proggie d/loads the whole web page?

    Beauregard T. Shagnasty, Jun 29, 2010, in forum: HTML
    Replies:
    1
    Views:
    437
    Beauregard T. Shagnasty
    Jul 2, 2010
  5. Raymond Schmit
    Replies:
    0
    Views:
    424
    Raymond Schmit
    Jun 30, 2010
Loading...

Share This Page