Searching for a random node in an XML document.
Posted on 2005-03-07
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 5> this is node 5 value </Node 5>
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.