views:

13

answers:

3
  Set objNoFormCheckXMLDOM = CreateObject("Microsoft.XMLDOM")
  objNoFormCheckXMLDOM.async = "false"
  objNoFormCheckXMLDOM.setProperty "SelectionLanguage", "XPath"
  objNoFormCheckXMLDOM.LoadXML(strHtmlResponse)
  Set nlForms = objNoFormCheckXMLDOM.selectNodes("form")

I have the above VBScript in a function. strHtmlResponse contains the markup as a string, I want to be able to check it for a form element, at any level including the root. The above example doesn't return any nodes in the nlForms nodelist. Anyone know how I can do this?

Thanks

A: 

Try //form as your xpath expression. The // means to include all descendant nodes in the search.

AndyC
I'm not sure if // checks the root node, but I tried changing strHtmlResponse to = "<form id=""test""><span class=""label"">Text</span><input /><input /></form>" and that works and I can do nlForms.length > 0 .. I think the original HTML is invalid XHTML and I thought it would throw an error if that occurred but it looks like it is not.
Pricey
A: 

Yea says here: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx

XmlException

There is a load or parse error in the XML. In this case, the document remains empty.

I will have to attempt doing this with regex instead unless someone has a better suggestion.

Pricey
+1  A: 
Set nlForm = objNoFormCheckXMLDOM.SelectSingleNode("//form") 

If Not nlForm Is Nothing

rem nlForm contains the first form element in the XML document
Dimitre Novatchev
This is what I did except my markup was not XHTML valid so it didnt give me any result, therefore I used regex instead due to the situation.
Pricey