To read A. xml file in. Net:

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.