It is much easier to read Xml fields first and then use Js for operations. Therefore, some methods for JS to read Xml field information are searched online in a project, we need to put the information table in the Xml field in the database on the page, if you use SQL for operations, read. In this case, it would be too complicated, so I thought it would be much easier to read the Xml field first and then operate it with Js, so I found some information on the Internet. The method for JS to read Xml field information is implemented.
First, we put a TextBox on the page to put Xml fields. Note: Label is unavailable, because in case of the "" symbol in the Xml field information, the page will produce a Js error.
The next step is the focus. Fu JS Code:
function createXml(str){ if(document.all){ var xmlDom=new ActiveXObject("Microsoft.XMLDOM") xmlDom.loadXML(str) return xmlDom } else return new DOMParser().parseFromString(str, "text/xml") }
// The above method is to instantiate the string as Xml
Finally, the Xml is operated.
Window. onload = function () {var str = document. getElementById ("ctl00_ContentPlaceHolder1_TextBox1 "). value; var obj = createXml (str); // obtain the root node var root_node1_obj.doc umentElement; var yh1 = ""; for (I = 0; I <root_node.childNodes [0]. childNodes. length-1; I ++) {yh1 + = "" + (I + 1) + "," + root_node.childNodes [0]. childNodes [I]. getAttribute ("Remark") + ":" + root_node.childNodes [0]. childNodes [I]. firstChild. nodeValue; yh1 + ="
"} Document. getElementById (" ctl00_ContentPlaceHolder1_lblContent "). innerHTML = yh1 ;}}
Xml format:
100
100
0
0