zoukankan      html  css  js  c++  java
  • XML读取事例程序

    data.xml 数据文件

    1 <?xml version="1.0" encoding="utf-8" ?>
    2  <root>
    3  <row ID="1" COMPNAME="DALIAN" POST="063000" TEL="0315-2695" LEVEL="888888888"/>
    4  <row ID="2" COMPNAME="TIANJUN" POST="063000" TEL="0315-2695" LEVEL="888888888"/>
    5  <row ID="3" COMPNAME="BEIJIN" POST="063000" TEL="0315-2695" LEVEL="888888888"/>
    6  </root>

    读取程序一:遍历全部节点

    <%
    Dim xml,objNode,objAtr,nCntChd,nCntAtr
    Set xml=Server.CreateObject("Microsoft.XMLDOM")

    xml.Async
    =False
    xml.Load(Server.MapPath(
    "data.xml"))
    Set objNode=xml.documentElement

    nCntChd
    =objNode.ChildNodes.length-1
    For i=0 to nCntChd

    Set objAtr=objNode.ChildNodes.item(i)
    nCntAtr
    =objAtr.Attributes.length-1

    For j=0 To nCntAtr
    response.write objAtr.Attributes.item(j).Text
    &"<br>"
    Next

    Response.Write
    "<br>"
    Next

    Response.Write
    "<br>"

    Set objAtr=Nothing
    Set objNode=Nothing
    Set xml=Nothing
    %
    >

     读取程序二:获取“COMPNAME”节点的内容

    <%
    Dim xml,objNode,objAtr,nCntChd,nCntAtr
    Set xml=Server.CreateObject("Microsoft.XMLDOM")

    xml.Async
    =False
    xml.Load(Server.MapPath(
    "data.xml"))
    Set objNode=xml.documentElement

    nCntChd
    =objNode.ChildNodes.length-1
    For i=0 to nCntChd

    Set objAtr=objNode.ChildNodes.item(i)
    nCntAtr
    =objAtr.Attributes.length-1

      response.write objAtr.Attributes.item(i).Text&"<br>"
    Next

    Response.Write
    "<br>"

    Set objAtr=Nothing
    Set objNode=Nothing
    Set xml=Nothing

    %
    >
    我来自:向东博客
  • 相关阅读:
    poj 3616 Milking Time
    poj 3176 Cow Bowling
    poj 2229 Sumsets
    poj 2385 Apple Catching
    poj 3280 Cheapest Palindrome
    hdu 1530 Maximum Clique
    hdu 1102 Constructing Roads
    codeforces 592B The Monster and the Squirrel
    CDOJ 1221 Ancient Go
    hdu 1151 Air Raid(二分图最小路径覆盖)
  • 原文地址:https://www.cnblogs.com/meil/p/ReadXml.html
Copyright © 2011-2022 走看看