Home >Web Front-end >JS Tutorial >Examples of using javascript to access XML data_javascript skills

Examples of using javascript to access XML data_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:22:18953browse

Among web browser software, Internet Explorer (IE) is now a standard software. As you can see, almost every machine running a different version of the Windows operating system (and many other operating systems) uses IE. Microsoft has included the functionality of IE in implementing mature XML processing technology through ActiveX controls.

In this article, we will describe how to use ActiveX features in IE to access and parse XML documents, thereby allowing web surfers to manipulate them.

Surfing the Internet
We start with a standard sequential document, as shown in Table A. This document contains simple sequential data for browsing by web surfers. Not only to display this data, we also provide a simple user interface that anyone surfing the Internet can use to browse XML documents.

Table A: order.xml


9900234

1234
5.95
100
595.00
Super Widget Clamp


 6234
22.00
10
Mighty Foobar Flange

9982

2.50 > 2500.00
DELUXE DOOHICKIE


3256 389.00
 
1
 389.00
 Muckalucket Bucket

1111
3704.00
07/07/2002

8876

We use a web form to Accessing this XML document, the form will display the SKU, price, quantity, subtotal for each part, and a description of each option in the sequence. Our form also contains buttons for forward and backward browsing options. Composition of a web page
The important part of a web page is the form. We will use a table to display it on the screen in an easy-to-read manner. The following is a code snippet to display an HTML table:


 
 
 
  Total
 
SKU
Price
Quantity
Description name="Description">


   SKU
   Price
   Quantity
   Total
   Description name="Description">
type="button" value=" >> " onClick="getDataNext();">

Please note that we include two buttons below the table, which are to browse the previous page through the getDataNext() and getDataPrev() functions. The record of one and the next is also what we want to discuss.

Script
In fact, the essential part of our webpage is not the form, but the script that controls the form. Included in our script are four parts. First, we initialize the web page by loading an XML document. The second part is to navigate to the next record. The third step is to navigate to the previous record. The fourth part is to extract a single value from the XML document. Table B shows the entire content of our web page.

Table B: jsxml.html







XML order Database



 
SKU
Price

  
  
  
  
  
SKU
Price
Quantity name="Quantity">
Total
Description name="Description">
Quantity

  name="Quantity">   Total td>   Description name="Description">
type="button" value=" >> " onClick="getDataNext();">




Run
This page will pass in and run the initialization of the script. You must make sure that the order.xml document is in the same path as jsxml.html.

The initialization part instantiates a new ActiveX object as the MSXML2.DOMDocument.3.0 object type, and then the script passes the order.xml document into memory and selects all /Order/Item nodes. We use the /Order/Item node to identify the options that the document already contains. The
standard in the
document has an onLoad attribute, which enables the web page to be initialized by calling getDataNext(). This feature can be used to get the next value from an XML document and display it in a form. We use a simple index to access specific options.

Both the forward (>>) and backward (
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn