How to use Javascript to read Xml field _ javascript in an SQL statement

Source: Internet
Author: User
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
   
  
 
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.