XML Document to XSD To Strong Typed Class
Convert XML to XSD to Class
From a command prompt run the following statements to convert first to an XSD then to a CS file.
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin>xsd c:\myXML.xml /out:c:\
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin>xsd c:\myXML.xsd /out:c:\ /classes /language:CS
Then move the XML and XSD to your web application’s APP_Data for safe keeping and move the cs file to App_Code folder. Then load and read the XML data.
XML
1: <?xml version="1.0" encoding="utf-8" ?>
2: <links>
3: <link title="Yahoo" url="www.yahoo.com" />
4: <link title="Google" url="www.google.com" />
5: <link title="Bing" url="www.bing.com" />
6: <link title="Asp.Net" url="www.asp.net" />
7: <link title="MSN" url="www.msn.com" />
8: </links>
CODE
1: System.IO.StreamReader str = new System.IO.StreamReader(document);
2: System.Xml.Serialization.XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(links));
3: links links = (links)xSerializer.Deserialize(str);
4: foreach (linksLink l in links.Items)
5: {
6: litXMLReader.Text += l.title + " : " + l.url + "<br />";
7: }
8: str.Close();
9:
10: litXMLReader.Text += "";