在VBScript中使用Microsoft.XMLHTTP使用XPATH解析XHTML [英] Parsing XHTML with XPATH using Microsoft.XMLHTTP in VBScript

查看:68
本文介绍了在VBScript中使用Microsoft.XMLHTTP使用XPATH解析XHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用VBScript中带有XPATH的Microsoft.XMLHTTP解析xhtml文档的方法.我具有以下xhtml文档结构.我如何获取网址数组?

I'm looking to parse an xhtml document with Microsoft.XMLHTTP with XPATH in VBScript. I have the following xhtml document structure. How would I get an array of the urls?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Local index</title>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <a href="url1.html">url1</a><br/>
                    <a href="url2.html">url2</a><br/>
                    <a href="url3.html">url3</a>
                </td><td>
                    <a href="url1-1.html">url1-1</a><br/>
                    <a href="url2-1.html">url2-1</a><br/>
                    <a href="url3-1.html">url3-1</a>
                </td>
            </tr>
        </table>
    </body>
</html>

推荐答案

确定要使用过时的程序ID Microsoft.XMLHTTP吗?这些天以来,MSXML 3和MSXML 6都是OS各自支持的Service Pack的一部分,自Windows XP以来便已提供任何支持. 至于使用XPath和MSXML 3,下面是一个示例:

Are you sure you need to use the antiquated program id Microsoft.XMLHTTP? These days both MSXML 3 as well as MSXML 6 are part of the OS respectively supported service packs with anything since Windows XP. As for using XPath and MSXML 3, here is an example:

Dim doc
Set doc = CreateObject("Msxml2.DOMDocument.3.0")
doc.validateOnParse = False
doc.resolveExternals = False
If doc.load("file.xml") Then
  doc.setProperty "SelectionLanguage", "XPath"
  doc.setProperty "SelectionNamespaces", "xmlns:xhtml='http://www.w3.org/1999/xhtml'"
  For Each link In doc.selectNodes("//xhtml:a")
    WScript.Echo(link.getAttribute("href") & ": " & link.text)
  Next
Else
  WScript.Echo(doc.parseError.reason)
End If

这篇关于在VBScript中使用Microsoft.XMLHTTP使用XPATH解析XHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆