Evaluate the basic XML Example of DOM operation. Evaluate the example of DOM adding, deleting, querying, modifying, and replacing XML .. No good examples can be found on the Internet. Everyone has a collection, a self-written, and practical work. please post it or send it to my EMAIL. Email: dada20042030@163.com,Index.html File: & lt; script & gt basic example of DOM operation XML
Evaluate the example of DOM adding, deleting, querying, modifying, and replacing XML ..
No good examples can be found on the Internet. Everyone has a collection, a self-written, and practical work. please post it or send it to my EMAIL.
Email: dada20042030@163.com
------ Solution --------------------
Index.html file:
Script
Var xmlDoc;
Function hehe ()
{
If (window. ActiveXObject)
{
XmlDoc = new ActiveXObject ("Microsoft. XMLDOM ");
XmlDoc. onreadystatechange = function ()
{
If (xmlDoc. readyState = 4)
{
HandleXmlDoc ();
}
}
XmlDoc. load ("data. xml ");
}
Else if (document. implementation & document. implementation. createDocument)
{
XmlDoc = document. implementation. createDocument ('','', null );
XmlDoc. onload = handleXmlDoc;
XmlDoc. load ("data. xml ");
}
}
Function handleXmlDoc ()
{
Var root=xmlDoc.doc umentElement;
Var info = root. getElementsByTagName ("info") [0];
Var result = info. firstChild. nodeValue;
Alert (result );
}
Window. onload = hehe;
Script
Xml file:
HelloWorld
------ Solution --------------------
It's too lazy. go to the next "xmlsdk30.chm" and get everything right away.
------ Solution --------------------
I found one for you.
Http://blog.csdn.net/zzj9898/archive/2007/04/06/1553917.aspx
Check it out
------ Solution --------------------
The above is written in JAVA. let's take a look at the following example:
1. an XML file (bookstore. xml) is known as follows:
Oberon's Legacy
Corets, Eva
5.95
1. forward Insert Node:
XmlDocument xmlDoc = new XmlDocument ();
XmlDoc. Load ("bookstore. xml ");
XmlNode root = xmlDoc. SelectSingleNode ("bookstore"); // search
XmlElement xe1 = xmlDoc. CreateElement ("book"); // create Node
Xe1.SetAttribute ("genre", "Lizan red"); // you can specify the genre attribute of the node.
Xe1.SetAttribute ("ISBN", "2-3631-4"); // you can specify the ISBN attribute of the node.
XmlElement xesub1 = xmlDoc. CreateElement ("title ");
Xesub1.InnerText = "CS from entry to entry"; // set a text node
Xe1.AppendChild (xesub1); // add Node
XmlElement xesub2 = xmlDoc. CreateElement ("author ");
Xesub2.InnerText = "Hou Jie ";
Xe1.AppendChild (xesub2 );
XmlElement xesub3 = xmlDoc. CreateElement ("price ");
Xesub3.InnerText = "58.3 ";
Xe1.AppendChild (xesub3 );
Root. AppendChild (xe1); // add Node
XmlDoc. Save ("bookstore. xml ");
// ==========================
Result:
Oberon's Legacy
Corets, Eva
5.95
CS from entry to entry
Hou Jie
58.3
2. modify the node: change the genre value of the node whose genre attribute value is "Li zanxiang" to "update Li zanxiang", and change the text of the child node of the node to "Yasheng ".
XmlNodeList nodeList = xmlDoc. SelectSingleNode ("bookstore"). ChildNodes; // obtain all the subnodes of the bookstore node
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.