[Asp.net] XML operations

Source: Internet
Author: User
Previously, an XML operation was performed. Some of them are vertex values.

The following generation:
Public Dataview getdata ( String Xmlpathnode)

{

// Get XML date, return dataview

Try

{

Stringreader read= NewStringreader (objxmldoc. selectsinglenode (xmlpathnode). outerxml );

DS. readxml (read );

}

Catch

{

Objerror. programerror ();

}

If (Ds. Tables. Count =   0 )

{

Return NewDataview ();

}

Return DS. Tables [ 0 ]. Defaultview;

}

This method is used to retrieve the specified vertex and value in XML data records. Later, I changed my next generation to a friend:
Public Dataview getdata ( String Xmlpathnode)

{

// Get XML date, return dataview

Try

{

// System. Io. stringreader READ = new system. Io. stringreader (objxmldoc. selectsinglenode (xmlpathnode). outerxml );

Xmlnodelist xnl = Objxmldoc. getelementsbytagname (xmlpathnode );

System. Text. stringbuilder strxml =   New System. Text. stringbuilder ();

Strxml. append ( " <? XML version = '1. 0'?> <Root> " );

For ( Int I = 0 ; I < Xnl. Count; I ++ )

{

Strxml. append (xnl [I]. outerxml );

}

Strxml. append ( " </Root> " );

System. Io. stringreader read =   New System. Io. stringreader (strxml. tostring ());

DS. readxml (read );

}

Catch

{

//

}

Return DS. Tables [ 0 ]. Defaultview;

}

This method is used to retrieve all xmlpathnode vertices and values, regenerate an XML file, and return dataview.

The difference between the two methods is that the former uses the specified vertex and the latter uses all the vertex.

Related Article

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.