Searching for a random node in an XML document.

Posted on 2005-03-07
Medium Priority
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:

   <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>


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.
Question by:mromeo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 10

Accepted Solution

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.,

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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