开发者

How do you use XPath to confirm whether a Form element is found in the passed in markup for loadXML?

  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?

Th开发者_如何学编程anks


Set nlForm = objNoFormCheckXMLDOM.SelectSingleNode("//form") 

If Not nlForm Is Nothing

rem nlForm contains the first form element in the XML document


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜