XML is not used for a long time. Recently, in the Silverlight project, you need to access some C ++ Dll through Web Service.
Use XML to pass data. Let's just review the XML operations.
Meteorology Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Xml;
Using System. IO;
Namespace HCLoad. Web
{
Public partial class TestXml: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
LoadXml ();
}
Private void LoadXml ()
{
XmlDocument xmlDoc = new XmlDocument ();
String strXml =
@ "<? Xml version = "" 1.0 "" encoding = "" UTF-16 ""?>
<Projects>
<Project id = "1"> p1 </project>
<Project id = "2" ">
<Name> p2 </name>
</Project>
</Projects> ";
XmlDoc. LoadXml (strXml );
// Response. Write ("<script> alert (" + xmlDoc. OuterXml + "); </script>"); // OuterXml is all content contained by this node
// Response. Write (xmlDoc. OuterXml); // the xml document output directly in the browser is blank because the browser cannot parse these labels.
// Query by Attribute Value
XmlElement theProject = (XmlElement) xmlDoc. DocumentElement. SelectSingleNode ("/projects/project [@ id = 1]");
Response. Write (theProject. InnerText );
// Query by subnode Value
XmlElement theProject2 = (XmlElement) xmlDoc. DocumentElement. SelectSingleNode ("/projects/project [name = p2]");
Response. Write (theProject2.InnerText); // note that the layer of name is queried.
// Query by Tag Name and modify
XmlDoc. GetElementsByTagName ("project"). Item (0). InnerText =