/// <Summary> /// Method for reading XML /// </Summary> /// <returns> </returns> public list <people> getxml () {list <people> List = new list <people> (); xmldocument xmldoc = new xmldocument (); // obtain the physical path string Path = server. mappath ("/content/user. XML "); // load the XML document xmldoc. load (PATH); // The first node xmlnode = xmldoc. selectsinglenode ("catalog"); // traverses the subnode foreach (xmlnode node in xmlnode) {list. add (new people ()
{Name = node. childnodes [0]. innertext,
Sex = node. childnodes [1]. innertext,
Age = convert. toint32 (node. childnodes [2]. innertext ),
Description = node. childnodes [3]. innertext
});} Return list ;}
<?xml version="1.0" encoding="utf-8"?><CATALOG> <people> <name>wuboo</name> <sex>man</sex> <age>21</age> <description>You’re more than a shadow, I’ve just to believe.</description> </people> <people> <name>laqi</name> <sex>man</sex> <age>24</age> <description>Remember, always laugh when you can. It‘s cheaper than medicine. </description> </people> <people> <name>masa</name> <sex>woman</sex> <age>23</age> <description>From now on, I will expect nothing, and just take what I get.</description> </people></CATALOG>
C # Read XML