method One: Using an XML control
Code
Copy Code code as follows:
<% @ Page language= "C #"%>
<body>
<from runat=server>
<asp:xml id= "XML1" documentsource= "Grade.xml" runat= "Server"/>
</from>
</body>
method Two: Using DOM technology
Code
Copy Code code as follows:
<% @ 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
Code
Copy Code code as follows:
<% @ 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>
method Four: read as text
Code
Copy Code code as follows:
<% @ Page language= "C #"%>
<% @ Import namespace= "System.Xml"%>
<script language= "C #" runat= "Server" >
private void Page_Load (Object Sender,eventargs E)
{
XmlTextReader objxmlreader=new XmlTextReader (Server.MapPath ("Grade.xml"));
String strnoderesult= "";
XmlNodeType Objnodetype;
while (Objxmlreader.read ())
{
Objnodetype =objxmlreader.nodetype;
Swith (Objnodetype)
{
Case Xmlnodetype.xmldeclaration:
Read XML file Headers
strnoderesult+= "XML declaration:<b>" +objxmlreader.name+ "" +objxmlreader.value+ "</b><br/>";
Break
Case XmlNodeType.Element:
Read tags
strnoderesult+= "element:<b>" +objxmlreader.name+ "</b><br/>";
Break
Case XmlNodeType.Text:
Read value
strnoderesult+= "-value:<b>" +objxmlreader.value+ "</b><br/>";
Break
}
Determine if the node has attributes
if (objxmlreader.attributecount>0)
{//All nodes are judged by loops
while (Objxmlreader.movetonextattibute)
{//Tag and value
strnoderesult+= "-attribute:<b>" +objxmlreader.name+ "</b> value:<b>" +objxmlreader.value+ "</b" ><br/> ";
}
}
Lblfile.text=strnoderesult;
}
}
</script>
<body>
<from runat=server>
<asp:label id= "lblfile" runat= "Server"/>
</from>
</body>