Using XMLTextReader to loop thru nodes/attributes

How can I loop thru the nodes and attributes (getting the values for each), assigning a variable name to each node value, also how can I get specific types from those nodes?

This is what needs to be parsed:
<Configuration>

<Server name = "a">
<IP>127.0.0.1</IP>
<Type>1</Type>
<Patch>2, 1, 1 6643</Patch>
<Signature></Signature>
<IsOffline>0</IsOffline> // boolean
</Server>

<Server name = "a">
<IP>127.0.0.2</IP>
<ServerType>2</ServerType>
<Patch>2, 1, 1 6641</Patch>
<Signature></Signature>
<IsOffline>0</IsOffline> // boolean
</Server>

<Updater>
<CurrentVersion>1.0.0</CurrentVersion>
<IsCriticalUpdate>1</IsCriticalUpdate> // boolean
<Signature>sdsa323h234jkh23kh324</Signature>
<DownloadLink>www.google.com</DownloadLink>
<NeedsUnpacked></NeedsUnpacked> // boolean
<Message></Message>
</Updater>

<Misc>
<BannedUser>24A33FTU53BN5F3AA34</BannedUser>
</Misc>

</Configuration>

The nodes that have "// boolean" need to be gathered from the parsing as so. Thanks so much.

Why does this code keep throwing an exception?
static void Main(string[] args)
{
//SelectQuery query = new SelectQuery("Select * from Win32_DiskDrive where DeviceId='c:'");

ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * FROM Win32_DiskDrive WHERE Index = 0");

foreach (ManagementObject mo in searcher.Get())
{
Console.WriteLine(mo["SerialNumber"].ToString());

}

Console.Read();
}

PS. I'm using C# by the way.

[1915 byte] By [Kyle12] at [2008-1-10]
# 1

I personally would use a DataSet - It is probably the best practice anyway

Here is a good example

http://support.microsoft.com/kb/311566

Code Snippet

string myXMLfile = "C:\\MySchema.xml";
DataSet ds = new DataSet();
try
{
ds.ReadXml(myXMLfile);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}

Ken_L at 2007-10-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 2
The problem is that the text you posted is NOT xml. Comments in XML begin with <!-- and end with -->.
timvw at 2007-10-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 3

Here is an example how to parse that data with XPathNavigator:

Code Snippet

XPathNavigator navigator = new XPathDocument("file.xml").CreateNavigator();
XPathNodeIterator nodeIterator = navigator.Select("Configuration/Server/*[contains(following-sibling::text()[1], '// boolean')]");
while (nodeIterator.MoveNext())
{
Console.WriteLine("Found element with name \"{0}\" and value \"{1}\".", nodeIterator.Current.Name, nodeIterator.Current.Value);
}

Using XmlReader/XmlTextReader is also possible but more difficult to code as XmlReader works forwards only while that (by the way badly designed XML format) sometimes has an element followed by some text node and only when you read the text node you know that the element node is what you are looking for.
MartinHonnen at 2007-10-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 4

Would this also work if I provided a URL to parse through, rather than a local file?

Kyle12 at 2007-10-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 5

Sure, jsut check the API for XPathDocument, the constructor http://msdn2.microsoft.com/en-us/library/system.xml.xpath.xpathdocument.xpathdocument.aspx has several overloads and the one with a string argument http://msdn2.microsoft.com/en-us/library/te0h7f95.aspx takes that argument as a URI.

MartinHonnen at 2007-10-3 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified