0

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")
Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Neta
  • 871
  • 5
  • 14
  • 30
  • 1
    Show us a sample of the XML input document. It probably has 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")`). – Martin Honnen Aug 01 '13 at 12:13
  • You are amazing!! That was the exact problem, even same link. We found out about it and came to search online, then we saw your answer. Can you please explain what you did here? And what is "default namespace declaration"? Thank you! – Neta Aug 01 '13 at 12:29
  • I posted an answer with some explanations and some links to explain XML and namespaces and how to script them with MSXML. – Martin Honnen Aug 01 '13 at 12:50

2 Answers2

1

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.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
0

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.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110