I need to determine the number of instances of a particular element within an XML document. I load the document using "XML Document Define" and then execute my XPath query using "Read XML Value to Variable". My XPath uses count to retrieve an integer: count(//errors).
"Read XML Value to Variable" reports "XPath returned no node". Should I be using another action to accomplish this XPath query?
Thanks.
How does your XPath look like? And your XML? It looks like the XPath isn’t returning any nodes at all.
You could also use the XML node iterator and update your count within each iteration. Not as fast, but should be a workaround.
Well, I’m sure the XPath query works because I tested it against actual XML output using Stylus Studio’s XPath evaluator. I’m using the XML node iterator as a workaround.
Thanks.
Hi Jeff,
The “Read XML Value to Variable” expects the XPath will return one or more XML nodes. On the other hand, evaluating the count() function will give you a number (I’m not actually sure how this is represented in MSXML DOM.)
There is no generic XML DOM action at the moment, so the XML Node iterator is the only “pure” FinalBuilder way. The other option would be to use a Run Script action with JScript/VBScript to load the XML document into DOM and then run the XPath query. The following links should help you get started:
JScript: http://msdn2.microsoft.com/en-us/library/ms761349.aspx
VBScript: http://www.xmlfiles.com/dom/dom_access.asp
Hth.
- Angus