How to fill a datagridview with parts of a xml file in c# windows forms?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello!
Unfortunately Im inexperienced in working with XML in C# and I cant find an answer to my task anywhere. Hopefully one of you can help me.
Ive a given xml-file which is validated by an external schema. In the end I want to read a part of its values beginning with a certain node to a datagridview in which I would like to load some internal data from a datatable and
check if both values are identical. A check if the file is valid would also be great. The file has many childs, so if do the normal reading like:
<pre class="prettyprint string file = "C:/temp/name.xml";
DataSet ds = new DataSet();
ds.ReadXML(file);
dataGridView1.DataSource = ds.Tables[0].DefaultView;[/code]
Iwill only geht the first childs into my datagridview.
I found another code, which works a little bit better, because I get all values, but I dont have their description (the elements name) and I dont want them in a listBox but in a datagridview. Plus I dont need all values but only a a certain part.
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
<pre class="prettyprint XmlTextReader objTxtRd;
objTxtRd = new XmlTextReader(file);
try
{
while (objTxtRd.Read())
{
if (objTxtRd.NodeType == XmlNodeType.Text)
{

listBox1.Items.Add(objTxtRd.Value);
}
}
}[/code]
So here is a kind of example of my xml, hopefully someone can tell my how to get its values and names to two columns in a datagridview starting with <WITHOUT> until the end, because the first part is always the same. If he can also
tell my how to check if the file il valid would be perfect!!!
Thanks a lot
<pre class="prettyprint <?xml version = "1.0" encoding = "iso-8859-1"?>
<LIEFERUNG xmlns="http://blah" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://blahh.xsd" version="1.0" erstellzeit="2012-08-15T15:11:31" stufe="Produktion" bereich="Statistik
<CUSTOMER>
<NAME>Johnson</NAME>
<STREET>Oxford Street</STREET>
<CONTACT>
<FAX>0123456</FAX>
<EMAIL>office@blah.net</EMAIL>
</CONTACT>
</CUSTOMER>
<FOOD erstellzeit="2012-08-15T15:11:31
<CUSTOMER2>
<NAME>Johnson</NAME>
<STREET>Oxford Street</STREET>
<CONTACT>
<FAX>0123456</FAX>
<EMAIL>office@blah.net</EMAIL>
</CONTACT>
</CUSTOMER2>
<MONTH>2012-07</MONTH>
<WITHOUT>
<COMPANY>Johnson and son</COMPANY>
<NUMBER>456789</NUMBER>
<ARTIKLES />
<BOOKS>
<SUM>12345</SUM>
<EBOOKS>
<AUTHOR>MEYER</AUTHOR>
<TITLE>World</TITLE>
<PRICE>9.24</PRICE>
<WAEHRUNG>EUR</WAEHRUNG>
</EBOOKS>
<EBOOKS>
<AUTHOR>MULLER</AUTHOR>
<TITLE>BRIDGE</TITLE>
<PRICE>10.24</PRICE>
<WAEHRUNG>EUR</WAEHRUNG>
</EBOOKS>
</BOOKS>
<CDS>
<SUM>1864</SUM>
<BLUB>
<PRICE>99</PRICE>
<WAEHRUNG>CHF</WAEHRUNG>
<LAND>DE</LAND>
</BLUB>
</CDS>
<OVERALLSUM>23456</OVERALLSUM>
<PARTS>100</PARTS>
<AVPRICE>170.95</AVPRICE>
</WITHOUT>
<BLUB>
<COMPANY>Johnson and son</COMPANY>
<NUMBER>456789</NUMBER>
</BLUB>
</FOOD>
</LIEFERUNG>[/code]
<br/>
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small












<span style="font-size:small <span style="font-size:small
<span style="font-size:small <span style="font-size:small
<br/>

View the full article
 
Back
Top