Which function do I use to retrieve a whole hierarchy?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Simpson

    Which function do I use to retrieve a whole hierarchy?

    I can build portions of DOM trees with jdom and xpathapi and using "new
    Element()" and "appendChil d()" 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.
  • David Carlisle

    #2
    Re: Which function do I use to retrieve a whole hierarchy?

    Scott Simpson <ssimpson@visio nsolutions.com> writes:
    [color=blue]
    > I can build portions of DOM trees with jdom and xpathapi and using "new
    > Element()" and "appendChil d()" 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.[/color]

    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

    Comment

    Working...