当前位置: 洪哥笔记 > ASP > VBScript之XMLDOM

 

VBScript之XMLDOM


关键词

VBScript之XMLDOM

摘要

VBScript之XMLDOM

         

XMLDOM 是用于读取XML数据的对象,下面是通过示例表示使用方法

dim xmlDoc
set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.Load("test.xml")

if xmlDoc.parseError.errorCode <> 0 then
     '发生错误
     MsgBox("错误说明:" & xmlDoc.parseError.reason)
else
     '显示数据
     dim i
     for i=0 to xmlDoc.childNodes(1).childNodes.length-1
         MsgBox(xmlDoc.childNodes(1).childNodes(i).childNodes(0).childNodes(0).nodeValue)
     Next
    
         Set arr = xmlDoc.getElementsByTagName("test")
     For Each i In arr
                MsgBox i.xml
         Next
         MsgBox arr.item(0).xml

end if

set xmlDoc = nothing

-------------------------------------------------------

async                          true为异步操作,false为同步操作,如果是同步操作则在读取完毕后再执行其它操作,所以一般为 false。
Load(xmlFilePath)              读取本地磁盘的 XML 文件。
LoadXML(xmlURL)                读取远程 XML 文件,或文本内容(如字符串)。
parseError                     错误信息对象,常用的属性是 errorCode 和 reason。
errorCode                      错误代码,0 表示没有发生错误。
reason                         错误的文字说明。
childNodes                     XML 子节点,子节点还可以包含子节点,数组形式,所以可以用 length 表示当前节点的子节点个数。第一个 xmlDoc.childNodes(0) 是 <?xml                                               version="1.0" encoding="gb2312"?>,xmlDoc.childNodes(1) 才是 XML “正文”。
nodeType                      节点类型
nodeTypeString                节点类型文字描述
nodeName                       节点名称
nodeValue                      节点值

-------------------------------------------------------

例子中的test.xml如下:

<?xml version="1.0" encoding="utf-8" ?>
<abc>
        <tt>
                <test>test1</test>
                <other></other>
        </tt>
        <tt>
                <test>test2</test>
                <other></other>
        </tt>
</abc>

 

 

要饭二维码

洪哥写文章很苦逼,如果本文对您略有帮助,可以扫描下方二维码支持洪哥!金额随意,先行谢过!大家的支持是我前进的动力!

文章的版权

本文属于“洪哥笔记”原创文章,转载请注明来源地址:VBScript之XMLDOM:http://www.splaybow.com/post/xmldom.html

如果您在服务器运维、网络管理、网站或系统开发过程有需要提供收费服务,请加QQ:8771947!十年运维经验,帮您省钱、让您放心!
亲,如果有需要,先存起来,方便以后再看啊!加入收藏夹的话,按Ctrl+D

« VBScript之调用命令行 VBScript之XMLHTTP »

相关文章: