MSXML2.DOMDocument.3.0从XML中读取数据
时间:2009-03-17 来源:zhou2324
先有一个XML数据:
Xml代码- <?xml version="1.0" ?>
- <Order>
- <Account>9900234</Account>
- <Item id="1">
- <SKU>1234</SKU>
- <PricePer>5.95</PricePer>
- <Quantity>100</Quantity>
- <Subtotal>595.00</Subtotal>
- <Description>Super Widget Clamp</Description>
- </Item>
- <Item id="2">
- <SKU>6234</SKU>
- <PricePer>22.00</PricePer>
- <Quantity>10</Quantity>
- <Subtotal>220.00</Subtotal>
- <Description>Mighty Foobar Flange</Description>
- </Item>
- <Item id="3">
- <SKU>9982</SKU>
- <PricePer>2.50</PricePer>
- <Quantity>1000</Quantity>
- <Subtotal>2500.00</Subtotal>
- <Description>Deluxe Doohickie</Description>
- </Item>
- <Item id="4">
- <SKU>3256</SKU>
- <PricePer>389.00</PricePer>
- <Quantity>1</Quantity>
- <Subtotal>389.00</Subtotal>
- <Description>Muckalucket Bucket</Description>
- </Item>
- <NumberItems>1111</NumberItems>
- <Total>3704.00</Total>
- <OrderDate>07/07/2002</OrderDate>
- <OrderNumber>8876</OrderNumber>
- </Order>
<?xml version="1.0" ?> <Order> <Account>9900234</Account> <Item id="1"> <SKU>1234</SKU> <PricePer>5.95</PricePer> <Quantity>100</Quantity> <Subtotal>595.00</Subtotal> <Description>Super Widget Clamp</Description> </Item> <Item id="2"> <SKU>6234</SKU> <PricePer>22.00</PricePer> <Quantity>10</Quantity> <Subtotal>220.00</Subtotal> <Description>Mighty Foobar Flange</Description> </Item> <Item id="3"> <SKU>9982</SKU> <PricePer>2.50</PricePer> <Quantity>1000</Quantity> <Subtotal>2500.00</Subtotal> <Description>Deluxe Doohickie</Description> </Item> <Item id="4"> <SKU>3256</SKU> <PricePer>389.00</PricePer> <Quantity>1</Quantity> <Subtotal>389.00</Subtotal> <Description>Muckalucket Bucket</Description> </Item> <NumberItems>1111</NumberItems> <Total>3704.00</Total> <OrderDate>07/07/2002</OrderDate> <OrderNumber>8876</OrderNumber> </Order>
然后把Item结点的数据读出。
相关的JS函数如下:
Js代码下面是测试网页代码:
Html代码- <body onload="getDataNext()">
- <form>
- <table border="0">
- <tr>
- <td>SKU</td>
- <td><input type="text" name="SKU"></td>
- </tr>
- <tr>
- <td>Price</td>
- <td><input type="text" name="Price"></td>
- </tr>
- <tr>
- <td>Quantity</td>
- <td><input type="text" name="Quantity"></td>
- </tr>
- <tr>
- <td>Total</td>
- <td><input type="text" name="Total"></td>
- </tr>
- <tr>
- <td>Description</td>
- <td><input type="text" name="Description"></td>
- </tr>
- </table>
- <input type="button" value="<<" onClick="getDataPrev()">
- <input type="button" value=">>" onClick="getDataNext()">
- </form>
- </body>
相关阅读 更多 +