Reputation: 901
I'm trying to get a value from a node in a .jdf file. It gives us an error
object required: 'curNode'
in line no. 13 - inputFolder = curNode.getAttribute("Amount")
We don't really know what to do... any help please?
Thank you
'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")
Upvotes: 0
Views: 174
Reputation: 167716
If an XPath expression like //JDF/ResourceLinkPool/ComponentLink
does not select elements in your input document then it is likely that you are processing a document which uses namespaces, see http://en.wikipedia.org/wiki/XML_namespaces.
With XPath 1.0 a path like /foo/bar
selects bar
child elements of foo
elements in no namespace while with an XML document of the form
<foo xmlns="http://example.com/ns1">
<bar>baz</bar>
</foo>
the elements are in the namespace http://example.com/ns1
.
With your sample there is probably a default namespace declaration (e.g. xmlns="http://www.CIP4.org/JDFSchema_1_1"
) which requires you to change your XPath expressions by defining a prefix for the namespace e.g.
xmlDoc.setProperty "SelectionNamespaces", "xmlns:jdf='http://www.CIP4.org/JDFSchema_1_1'"
and using it:
Set curNode = xmlDoc.selectSingleNode("//jdf:JDF/jdf:ResourceLinkPool/jdf:ComponentLink")
Documentation for MSXML is at http://msdn.microsoft.com/en-us/library/windows/desktop/ms756048%28v=vs.85%29.aspx.
Upvotes: 0
Reputation: 38775
To deal with the error, check
If curNode Is Nothing Then
...
Else
Dim inputFolder
...
End If
Obviously your assumptions (XPath expression) about the source file are wrong, when selectSingleNode() fails.
Upvotes: 1