The Xml field in the SQL for Javascript read operations, sqlxml

Source: Internet
Author: User

The Xml field in the SQL for Javascript read operations, sqlxml

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 + = "<br/>"} document. getElementById ("ctl00_ContentPlaceHolder1_lblContent "). innerHTML = yh1 ;}}

Xml format:

<Info Remark = "file template"> <Common Remark = ""> <DisCopy Remark = ""> 100 </DisCopy> <DisOriginal Remark = ""> 100 </DisOriginal> <ArrearageLimit Remark = "Max overdue payment"> 0 </ArrearageLimit> <YearPrice Remark = "annual fee, RMB/year "> 0 </YearPrice> </Common> </Info>

Javascript reads xml data

//////////////////////////////////////// ///////////////////
First, the content of the xml file (tree. xml) is as follows:
<? Xml version = "1.0" encoding = "gb2312"?>
<Treeview>
<Tree id = "p1">
<Text> Shandong </text>
<Target> _ blank </target>
<Title> province </title>
<Link> </link>
<Tree id = "p1-1">
<Text> Weihai </text>
<Target> _ blank </target>
<Title> city </title>
<Link> </link>
</Tree>
<Tree id = "p1-2">
<Text> Yantai City </text>
<Target> _ blank </target>
<Title> city </title>
<Link> </link>
<Node id = "p1-2-1">
<Text> Changyi village </text>
<Target> _ blank </target>
<Title> Villages and Towns </title>
<Link> www.baidu.com/</link>
</Node>
</Tree>
<Node id = "p1-3">
<Text> fuzhen </text>
<Target> _ blank </target>
<Title> Villages and Towns </title>
<Link>... the remaining full text>

JavaScript reads XML

Add this sentence:
XmlDoc. async = false;
Change it to the following.
Function read ()
{
Var xmlDoc = new ActiveXObject ("Microsoft. XMLDOM ");
XmlDoc. async = false;
XmlDoc. load ("lw_note.xml ");
Var items = xmlDoc. getElementsByTagName ("Note ");
Var name = items [0]. childNodes [0]. childNodes [0]. nodeValue;
}

The async attribute specifies whether the XML file download should be processed synchronously.
True means that the load () method can return control to the caller before the download is complete.
False indicates that the download must be completed before the caller retrieves control.
Reference: www.w3school.com.cn/xmldom/prop_document_async.asp

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.