Working on my non existent C# XML skills ...
I sat down this morning and whipped up the following in about 10 minutes ...
The XML
<Format version="0.0.1">
<Product>
<Title>Title 5</Title>
</Product>
<Product>
<Title>Title 4</Title>
</Product>
<Product>
<Title>Title 1</Title>
</Product>
<Product>
<Title>Title 2</Title>
</Product>
<Product>
<Title>Title 3</Title>
</Product>
<Property>
<Name>Property 1</Name>
<Setting>0xB100</Setting>
</Property>
<Property>
<Name>Property 3</Name>
<Setting>0xCFBA</Setting>
</Property>
<Property>
<Name>Property 2</Name>
<Setting>0xF824</Setting>
</Property>
</Format>
The Code
int i = 0;
XmlDataDocument xmlDoc = new XmlDataDocument();
textBox1.Text = String.Empty;
using (FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read))
{
xmlDoc.Load(fs);
}
XmlNodeList xmlNodeProducts = xmlDoc.GetElementsByTagName("Product");
textBox1.Text += "Products:" + Environment.NewLine;
for (i = 0; i < xmlNodeProducts.Count; i++)
{
// I would like to get the ChildNode by Name not Index. For example by "Title" or "Name" or "Setting".
textBox1.Text += "\t" + xmlNodeProducts[i].ChildNodes.Item(0).InnerText.Trim() + Environment.NewLine;
}
XmlNodeList xmlNodeProperties = xmlDoc.GetElementsByTagName("Property");
textBox1.Text += Environment.NewLine + "Properties:" + Environment.NewLine;
for (i = 0; i < xmlNodeProperties.Count; i++)
{
// I would like to get the ChildNode by Name not Index. For example by "Title" or "Name" or "Setting".
textBox1.Text += "\t" + xmlNodeProperties[i].ChildNodes.Item(0).InnerText.Trim() + Environment.NewLine;
}
Does just like I want for the time being with one minor exception ...
I'd like to be able to get the ChildNode by name ... See comments in above code.
However, XmlDataDocument is obsolete ... So I have spent the rest of the day trying to do this same thing in a non obsolete fashion to no avail.
Ultimately this is going to be an editor/diff tool for the xml file.
Any guidance would be much appreciated.
Thank You!
P.S. This Site and Editor is almost a worse disaster then the previous one ... New is not always better, this new Microsoft Q/A site is a good example of that.