To read A. xml file in. Net:
1. Use the xmltextreader class, such:
Xmltextreader reader = new xmltextreader (server. mappath (xmlpath ));
While (reader. Read ())
{
If (reader. nodetype = xmlnodetype. Text)
{
Response. Write (reader. Name + "DD" + reader. value );
}
}
2. Use the xpathnavigator class:
Xpathdocument xpdoc = new xpathdocument (server. mappath (xmlpath), xmlspace. Preserve );
Xpathnavigator xpnav = xpdoc. createnavigator ();
Xpathnodeiterator xpiter = xpnav. selectdescendants ("username", String. Empty, true );
// Response. Write (xpiter. Current. Name + xpiter. Current. value );
While (xpiter. movenext ())
{
If (xpiter. Current. value = "C21 ")
{}
}
3. Use the xmldocument class:
Xmldocument xdoc = new xmldocument ();
Xdoc. Load (server. mappath (xmlpath ));
Xmlnamespacemanager Mgr = new xmlnamespacemanager (xdoc. nametable );
Mgr. addnamespace ("C21", "http://52089.net ");
Xmlnodelist xlist = xdoc. selectnodes ("// user", MGR );
Foreach (xmlnode node in xlist)
{
If (node. childnodes [0]. innertext = "C21 ")
{
Response. Write ("Spring is coming! ");
}
}
4. Use the dataset class:
Dataset dsusers = new dataset ();
Dsusers. readxmlschema (pubpath + "\ userinfo. XSD"); // If yes
Dsusers. readxml (pubpath + "\ userinfo. xml"); required!
With the DataSet object, everything is easy to do, such:
Datarow rowuser = dsusers. Tables ["user"]. Rows. Find (username); // obtain the row object that meets the condition