asp.net read XML code (1/2)

Source: Internet
Author: User

Provides the simplest ASP tutorial. NET Read XML code program

New XDocument (
New XElement ("Ol",
From item in Xdocument.load (Http://111cn.net/update.xml). Descendants ("item")
Select New xelement[]{
New XElement ("Li",
New XElement ("A", (string) item.element ("title"),
New XAttribute ("href", (string) item.element ("link")
)
)
}
)
). WriteTo (New XmlTextWriter (Response.outputstream,encoding.utf8));

Method One: Using an XML control
<% @ Page language= "C #"%>

<body>
<from runat=server>
<asp Tutorial: xml id= "XML1" documentsource= "Grade.xml" runat= "Server"/>
</from>

</body>

Method two: Using DOM technology
<% @ Page language= "C #"%>
<% @ import namespace= "System.Xml"%>
<% @ import namespace= "System.Xml.Xsl"%>

<script language= "C #" runat= "Server" >
void Page_Load (Object Sender,eventargs e)
{
XmlDocument doc=new XmlDocument ();
Doc.load (Server.MapPath ("Grade.xml"));
Xml1.document=doc;
}
</script>
<body>
<from runat=server>
<asp:xml id= "XML1" runat= "Server"/>
</from>

</body>

Method Three: Working with a DataSet object
<% @ Page language= "C #"%>
<% @ import namespace= "System.Data"%>
<% @ import namespace= "System.Data.OleDb"%>
<script language= "C #" runat= "Server" >
void Page_Load (Object Sender,eventargs e)
{
DataSet objdataset=new DataSet ();
Objdataset.readxml (Server.MapPath ("Grade.xml"));
dgemployees.datasource=objdataset.tables["Student"].defaultview;
Dgemployees.databind ();
}
</script>
<body>
<asp:datagrid id= "dgemployees" runat= "Server"/>

</body>

Home 1 2 last page

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.