.net - How to read XML into a class/classes that matches its xsd -
Then I have an XSD and a webservice that delivers in the same format.
Now I can go ahead and read XML in a document, make my items from class etc. ... but I am thinking that there should be some easy way to do this.
Am I right? ;)
& lt; As a result xsi: schemaLocation = "karl: Yahoo: Maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd"> & Lt; Result precision = "address" & gt; & Lt; Latitude & gt; 47.643727 & lt; / Latitude & gt; & Lt; Longitude & gt; -122.130474 & lt; / Longitude & gt; & Lt; Address & gt; 1 Microsoft Way, # Way 1 & lt; / Address & gt; & Lt; City & gt; Redmond & lt; / City & gt; & Lt; State & gt; Washington & lt; / State & gt; & Lt; Pin & gt; 98052-6399 & lt; / Pin & gt; & Lt; Country & gt; America & lt; / Country & gt; & Lt; / Results & gt; & Lt; / ResultSet & gt;
You can use the xsd.exe sections to derive XML text in examples of sections generated by
> XmlSerializer will use metadata attributes on the generated classes to map back and forth between XML elements and objects.
string xmlSource = "& lt; ResultSet & gt; & lt result precision = \" address \ "& gt; & lt; latitude & gt; 47.643727 & lt; / latitude & gt; & Lt; / results & gt; & lt; / ResultSet & gt; "; XmlSerializer serializer = New XmlSerializer (Type ResultSet); Output as result; (Using the string reader reader = new string reader (XMLSOSR)) {output = (result-set) serializer. Dairyialize (Reader); }
Comments
Post a Comment