我正在尝试将文本放在此XML文件的特定属性中。例如,描述,类型等中的文本
目前我收到错误:
行:23
错误:需要对象:'objNode.attributes.getNameItem(....)'
如何访问加载XML文件的特定属性? description,details-> serviceName,type
<!DOCTYPE html>
<html lang="en">
<head>
<title>XML</title>
<HTA:APPLICATION
APPLICATIONNAME = "XPOS removal tool"
/>
</head>
<script language="VBScript">
Sub Window_onLoad
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load("programs1.xml")
strQuery = "/steps/step"
Set colNodes = xmlDoc.selectNodes( strQuery )
htmlString = "<table><tr><th>Description</th><th>Type</th><th>Status</th></tr>"
For Each objNode in colNodes
htmlString = htmlString & "<tr><td>"& objNode.attributes.getNamedItem("description").value &"</td><td>test</td></tr>"
// htmlString = htmlString & "<tr><td>"& objNode.text &"</td><td>test</td></tr>"
Next
htmlString = htmlString & "</table>"
DataArea.innerHTML = htmlString
End Sub
</script>
<body>
<div id="DataArea"></div>
</body>
</html>
XML数据:
<?xml version='1.0'?>
<steps>
<step>
<description>Description 1</description>
<type>Type 5</type>
<details>
<runFolder>c:\windows</runFolder>
<runFile>v3-x86.exe</runFile>
</details>
</step>
<step>
<description>Description 2</description>
<type>Type 4</type>
<details>
<serviceName>COMRedirector</serviceName>
<processName>COMRedirectorServ</processName>
</details>
</step>
<step>
<description>Description 3</description>
<type>Type 3</type>
<details>
<serviceName>OSUpdate</serviceName>
<processName>OSUpdateServ</processName>
</details>
</step>
</steps>
答案 0 :(得分:1)
您可以按.GetAttribute(...)
获取属性,而不是.Attributes.GetNamedItem(...)
。但是,在取消隐藏并查看您的实际XML数据之后:您首先不会查找属性。您想要选择XML节点的文本/值:
For Each objNode in xmlDoc.selectNodes("//description")
htmlString = htmlString & "<tr><td>" & objNode.text & _
"</td><td>test</td></tr>"
Next
答案 1 :(得分:0)
基本上这就是我想要做的。
v6[row][column]