Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Searching for a random node in an XML document.

Posted on 2005-03-07
1
Medium Priority
?
408 Views
Last Modified: 2012-06-21
I am trying to figure out an efficient way to search for a random node in an XML document.  I will not necessarily know the parent nodes prior to the search.  For example, if the XML is:

<Parent>
   <Node 1>some value </Node1>
   <Node 2> node 2 value</Node 2>
   <Node 3>node 3 value</Node 3>
   <Node 4>
              <Node 5> this is node 5 value </Node 5>
   </Node 4>

</Parent>

I will need to find the value for ANY of these nodes without knowing its Parent.  Anybody know of a quick way of doing this or do I need to traverse the entire tree til I find the node?   The nodes are guaranteed to be unique, so I don't have to worry about that.  I can't just use an xpath with wildcards, because I don't know how many levels deep to search.  Thanks.
0
Comment
Question by:mromeo
1 Comment
 
LVL 10

Accepted Solution

by:
BobSiemens earned 1000 total points
ID: 13481976
<xsl:value-of select="//Node5"/> will match node 5 anywhere in the hierarchy.

Note: it's <Node5> or <Node id="5"> but not <Node 5>

Also, that 'value-of' will match the first <Node5> -- there are ways of handling multiples.,
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question