Javascript + DOM access data in XML files

Source: Internet
Author: User
1. generate an XML file.
In ADO, use recordset. the Save method can save the query content to the specified XML file. In this way, the generated file contains a lot of data table attributes, that is, <s: schema> </s: schema> node content. What we need is the content of the <RS: DATA> </RS: DATA> node. The structure is roughly as follows: Data. xml
<XML...>
<S: schema>
...
</S: schema>
<RS: DATA>
<Z: Row positionid = '000000' positionname = 'fdsafsd' companyid = '1' pmid = '000000'/>
<Z: Row positionid = '000000' positionname = '. Net developer' companyid = '2' pmid = '000000'/>
</RS: DATA>
<Z: Row/> is a data row. The next step is to display this part.
2. loadxml file.
<Script language = JavaScript>
VaR xmldoc = new activexobject ("Microsoft. xmldom ");
VaR currnode;
Xmldoc. async = false;
Xmldoc. Load ("data. xml ");
If (xmldoc. parseerror. errorcode! = 0) {// if an error occurs while opening the file
VaR myerr = xmldoc. parseerror;
Document. Write ("You have error" + myerr. Reason );
}
Else
{
Document. Write ("<HR size = 1> ");
Xmldoc. setproperty ("selectionlanguage", "XPath ");
Currnode = xmldoc.doc umentelement. childnodes [1]; // obtain the <RS: DATA> section
Alert (currnode. childnodes [0]. attributes [0]. Value); // Test Result

For (I = 0; I <currnode. childnodes. length; I ++) // traverse each 'data row'
{
For (j = 0; j <currnode. childnodes [I]. Attributes. length; j ++) // traverse each attribute of a row
{
Document. write (currnode. childnodes [I]. attributes [J]. name + ":" + currnode. childnodes [I]. attributes [J]. value + "<br> ");
}
Document. Write ("<HR size = 1> ");
}
}
</SCRIPT>

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.