0

我正在尝试从 .jdf 文件中的节点获取值。它给了我们一个错误

object required: 'curNode'

行号 13 -inputFolder = curNode.getAttribute("Amount")

我们真的不知道该怎么做......请帮助?

谢谢

'creates the msxml object
Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
Dim xmlDataPath,retVal
xmlDataPath = "C:\Users\liatte\Desktop\Aviv Omer Neta\JDFs to Txt\a.jdf"

'load the xml data of the script
retVal=xmlDoc.load(xmlDataPath)

'get input folder
Set curNode = xmlDoc.selectSingleNode("//JDF/ResourceLinkPool/ComponentLink")
Dim inputFolder
inputFolder = curNode.getAttribute("Amount")
4

2 回答 2

1

要处理错误,请检查

If curNode Is Nothing Then
   ... 
Else
   Dim inputFolder
   ...
End If

显然,当 selectSingleNode() 失败时,您对源文件的假设(XPath 表达式)是错误的。

于 2013-08-01T12:01:05.140 回答
0

如果 XPath 表达式 like//JDF/ResourceLinkPool/ComponentLink没有选择输入文档中的元素,那么您可能正在处理使用名称空间的文档,请参阅http://en.wikipedia.org/wiki/XML_namespaces

使用 XPath 1.0 的路径类似于/foo/bar选择无命名空间bar中元素的子元素,foo而使用表单的 XML 文档

<foo xmlns="http://example.com/ns1">
  <bar>baz</bar>
</foo>

元素在命名空间中http://example.com/ns1

对于您的示例,可能有一个默认命名空间声明(例如xmlns="http://www.CIP4.org/JDFSchema_1_1"),它要求您通过为命名空间定义前缀来更改 XPath 表达式,例如

xmlDoc.setProperty "SelectionNamespaces", "xmlns:jdf='http://www.CIP4.org/JDFSchema_1_1'"

并使用它:

Set curNode = xmlDoc.selectSingleNode("//jdf:JDF/jdf:ResourceLinkPool/jdf:ComponentLink")

MSXML 的文档位于http://msdn.microsoft.com/en-us/library/windows/desktop/ms756048%28v=vs.85%29.aspx

于 2013-08-01T12:49:02.643 回答