我想用VBScript中的XPATH用Microsoft.XMLHTTP解析xhtml文档。我有以下xhtml文档结构。如何获取URL数组?
<!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
吗?如今,MSXML3和MSXML6都是自WindowsXP以来分别支持的操作系统服务包的一部分。关于使用XPath和MSXML3,这里有一个例子:
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