Try to use all the operations and attributes to do the demonstration
Copy Code code as follows:
<script language= "JavaScript" >
<!--
var doc = new ActiveXObject ("Msxml2.domdocument"); Ie5.5+,createobject ("Microsoft.XMLDOM")
Loading documents
Doc.load ("B.xml");
To create a file header
var p = doc.createprocessinginstruction ("xml", "version= ' 1.0 ' encoding= ' gb2312 '");
Add File Headers
Doc.appendchild (P);
To get the root contact when loading directly
var root = doc.documentelement;
Create root contacts in two ways
var root = doc.createelement ("Students");
var root = Doc.createnode (1, "Students", "");
Creating Child contacts
var n = doc.createnode (1, "Ttyp", "");
Specify Child Contact text
N.text = "This is a test";
Create Sun Contact
var o = doc.createelement ("Sex");
O.text = "male"; Specify its text
Creating properties
var r = doc.createattribute ("id");
r.value= "Test";
Add properties
N.setattributenode (R);
Create a second property
var r1 = Doc.createattribute ("class");
R1.value= "TT";
Add properties
N.setattributenode (R1);
Delete Second Property
N.removeattribute ("class");
Add Sun Contact
N.appendchild (o);
Add text Contacts
N.appendchild (Doc.createtextnode ("This is a text node.");
Add a Comment
N.appendchild (Doc.createcomment ("This is a comment\n"));
Add Child contacts
Root.appendchild (n);
Copy Contacts
var m = N.clonenode (true);
Root.appendchild (m);
Delete a contact
Root.removechild (root.childnodes (0));
Create a data segment
var c = doc.createcdatasection ("This is a CDATA");
C.text = "Hi,cdata";
Adding data segments
Root.appendchild (c);
Add Root Contact
Doc.appendchild (root);
Find Contacts
var a = Doc.getelementsbytagname ("Ttyp");
var a = Doc.selectnodes ("//ttyp");
Show the properties of the modified contact
for (var i= 0;i<a.length;i++)
{
alert (a[i].xml);
for (Var j=0;j<a[i].attributes.length;j++)
{
alert (a[i].attributes[j].name);
}
}
modifying nodes, using XPath to locate nodes
var B = Doc.selectsinglenode ("//ttyp/sex");
B.text = "female";
alert (doc.xml);
XML save (required on server, client with FSO)
Doc.save ();
View the root contact XML
if (n)
{
alert (n.ownerdocument.xml);
}
-->
</script>