Converting XML to c# class -
i receiving xml file on socket , want retrieve values inside xml converting c# class object
please guide me how this
i need values of sno,file,it , maxit
p.s. using visual studio 2010
here xml file:
<?xml version="1.0" standalone="yes"?> <newdataset> <default.xml> <sno>31</sno> <file>300k</file> <it>5</it> <maxit>10</maxit> </default.xml> <default.xml> <sno>32</sno> <file>200k</file> <it>5</it> <maxit>10</maxit> </default.xml> </newdataset>
[edited] please note need use these values dynamically working on utility sends xml file system via sockets. dont think can ude xsd here
to nodes use xpath expression /default/default. first slash means node must root node. selectnodes method returns collection xmlnodelist contain nodes. value of sub node can index xmlnode node name: xmlnode["sno"].innertext. see example below.
xmldocument xml = new xmldocument(); xml.loadxml(myxmlstring); // suppose myxmlstring contains "<default>...</default>" xmlnodelist xnlist = xml.selectnodes("/default/default"); foreach (xmlnode xn in xnlist) { string ss= xn["sno"].innertext; string vv= xn["file"].innertext; console.writeline("name: {0} {1}", ss, vv); }
Comments
Post a Comment