C# XML Parsing - Searching for specific elements

Reergeatollox

New Member
I'm using an \[code\]XMLReader\[/code\] in C# .net 4.0 to search through a small snippet of XML. I want to find specific elements in the XML, and I'm using the \[code\]XMLReader.ReadToFollowing("name")\[/code\] method to find the elements. I do not know the order in the XML document that the elements are; they be in a difference sequence or missing entirely. The order does not matter to me, but I will throw an exception if the element is missing.The XMLReader is forward only, so if the first element I'm looking for is the last value in the XML document, additional reads will fail.I was thinking of creating a new XMLReader for each search. I only have a small set of elements to find and the XML isn't huge so I don't think there will be much overhead, but I could be wrong.Is there a better library to use for searching XML when you do not know the order of the elements? Or is a lack of order in XML a violation of the XML specification?Specifically, let's say I have some simple XML. A head and 10 Children.\[code\]<sometag> <element1>data</element1> <element2>data</element2> . . . <element10>data</element10></sometag>\[/code\]Would it be inefficient to open 5 XMLReaders to find those elements? I could also use the one reader and step through each element, but then I would need to keep track of which elements I've found.
 
Back
Top