< Script Language = " Javascript " >
<! --
VaR Doc = New Activexobject ( " Msxml2.domdocument " ); // Ie5.5 +, Createobject ("Microsoft. xmldom ")
// document loading
// Doc. load ("B. XML);
// create a file header
var P = Doc. createprocessinginstruction ( " XML " , " Version = '1. 0 'encoding= 'gb2312' " );
//Add File Header
Doc. appendchild (P );
// Used to obtain the root contact during direct loading.
// VaR root = doc.doc umentelement;
// Two ways to create a root contact
// VaR root = Doc. createelement ("Students ");
VaR Root = Doc. createnode ( 1 , " Students " , "" );
//Create a Child Contact
VaRN=Doc. createnode (1,"Ttyp","");
// Specified stator contact text
// N. Text = "this is a test ";
// Create a sun contact
VaR O = Doc. createelement ( " Sex " );
O. Text = " Male " ; // Specify text
// Create attributes
VaR R = Doc. createattribute ( " ID " );
R. Value = " Test " ;
//Add attribute
N. setattributenode (R );
// Create the second property
VaR R1 = Doc. createattribute ( " Class " );
R1.value = " TT " ;
// Add attribute
N. setattributenode (R1 );
//Delete the second property
N. removeattribute ("Class");
//Add sun contact
N. appendchild (O );
//Add text contacts
N. appendchild (Doc. createtextnode ("This is a text node."));
// Add Comment
N. appendchild (Doc. createcomment ( " This is a comment \ n " ));
// ADD child contacts
Root. appendchild (N );
// Replication contacts
VaR M = N. clonenode ( True );
Root. appendchild (m );
//Delete contacts
Root. removechild (root. childnodes (0));
// Create Data Segment
VaR C = Doc. createcdatasection ( " This is a CDATA " );
C. Text = " Hi, CDATA " ;
// Add Data Segment
Root. appendchild (C );
// Add root contacts
Doc. appendchild (Root );
// Find contacts
VaR A = Doc. getelementsbytagname ( " Ttyp " );
// VaR A = Doc. selectnodes ("// ttyp ");
// Display attributes of change contacts
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 );
}
}
//Modify nodes and use XPath to locate nodes
VaRB=Doc. selectsinglenode ("// Ttyp/sex");
B. Text= "Female";
// Alert (Doc. XML );
// Save XML (on the server side and FSO on the client side)
// Doc. Save ();
// View root contact XML
If (N)
{
Alert (N. ownerdocument. XML );
}
//-->
</Script>