Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Which function do I use to retrieve a whole hierarchy?

Reply
Thread Tools

Which function do I use to retrieve a whole hierarchy?

 
 
Scott Simpson
Guest
Posts: n/a
 
      05-08-2005
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.
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      05-09-2005
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
 
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
Re: Which proggie d/loads the whole web page? Beauregard T. Shagnasty HTML 1 07-02-2010 02:42 AM
Re: Which proggie d/loads the whole web page? richard HTML 1 07-01-2010 12:57 AM
Re: Which proggie d/loads the whole web page? Raymond Schmit HTML 0 06-30-2010 10:32 PM
How can I write values in a properties-File which is located in a JAR without copying the whole JAR? stanislav.tomic@gmail.com Java 13 08-18-2007 08:41 PM
*WITHOUT* using: ValidateRequest="False" for the whole page (or my whole site).... \A_Michigan_User\ ASP .Net 2 08-21-2006 02:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57