Search XML in VBscript

本文介绍如何利用VBScript与MSXML版本6.0进行XML文件的搜索操作,详细说明了设置MSXML对象属性的方法,如使用XPath进行查询及处理XML命名空间等,并演示了如何加载XML文件及选取特定节点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Recently, in my project, there is a requirment that need to search specific XML node by using vbscript, in that, meet several issues and work out finally, so record these here.

 

1. MSXML Version

As we know, there are several versions of MSXML from 3.0 to 6.0, here is link to provides detail.

In my opinion, you'd better choose V6.0 if possible, it supports Xpath friendly.

 

2. How to use MSXML in VBScript

 

Dim MSXML
Set MSXML = CreateObject("MSXML2.DOMDocument.6.0") 'Create the MSXML object

 

There are also some basic properites you need to configure before you use the object

Async = true

preserverWhiteSpace = true

validateOnParse = true


 

here is one properties I like to highlight, it is

MSXML.setProperty "SelectionLanguage", "XPath"

 

It lets you can use XPATH in your code.

 

And if in your xml file, there is xml namespace, you also have to set

MSXML.setProperty"SelectionNamespaces","xmlns:prefix='http://www.gbxml.org/schema'"

 

After you set the proper properties of MSXML object, you can use Load() to load your xml file

MSXML.Load("/Analyzed.xml")

 

Next, it is very easy, like you use xpath in C# code, there are two methods let you select the specific XML node,

SelectSingleNode(SearchString)

SelectNodes( SearchString )

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值