Topic: How to use JavaScript to manipulate XML data according to (100) Author: JasonZhu (Jason) Grade: credit value: 100 Quantity Forum: Web Development JavaScript questions Points: 100 Replies: 4 Time: 2005-4-229: 38:39
How to use JavaScript operation XML data
I hope I can have a detailed documentation
Reply to: bguest (然 的 未)) () Reputation: 1002005-4-22 9:53:17 Score: 0?
VAR DOC = New ActiveXObject ("msxml2.domdocument"); //ie5.5 ,createObject ("Microsoft.xmldom")
// Load a document
//doc.load( "b.xml ");
// Create a file header
VAR P = Doc.createProcessinginstruction ("XML", "Version = '1.0' Encoding = 'GB2312');
// Add a file header
Doc.appendchild (p);
// Get root connections 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 sub-contacts
VAR n = doc.createnode (1, "TTYP", "");
// Specify sub-contact text
//n.text = "this is a test";
// Create a sun directly
Var o = doc.createElement ("sex");
o.Text = "Men"; // Specify its text
// Create an attribute
Var r = doc.createAttribute ("ID");
R.Value = "test";
// Add attribute
N.SetaTRibutenode (R);
// Create a second attribute
Var r1 = doc.createattribute ("class");
R1.Value = "tt";
// Add attribute
n.settributenode (r1);
/ / Delete the second attribute
N.RemoveAttribute ("class");
// Add Sun Jia
N.Appendchild (O);
// Add text contact
N.Appendchild (Doc.createTextNode ("This Is A Text Node.")
//add notes
N.Appendchild (Doc.createComment ("this is a comment / n");
// Add sub-contact
Root.Appendchild (n);
// Copy contact
Var m = n.clonenode (TRUE);
Root.Appendchild (M);
// Delete contact
Root.removechild (root.childnodes);
// Create a data segment
Var c = doc.createcdatasection ("this is a cdata");
C.Text = "Hi, CDATA";
// Add data segment
Root.Appendchild (C);
// Add root contact
Doc.Appendchild (root);
/ / Find contacts
VAR a = doc.get.GtelementsBytagname ("TTYP");
// var a = doc.selectnodes ("// TTYP");
// Display the properties of the change point