Jump to content

XML Parse question


 Share

Recommended Posts

Hello all. I have a question about XML parsing and xpath. I am extremely new to both so apologies if this is a basic question. I did search the forum and this link on w3schools as well as the MSDN documentation. I was working from (which was extemely helpful). Here is my problem: I can find a specific named node and then get some info from it which I need. However, I am having trouble finding that node with an alternative approach using "contains" to search for any node that contains a subset of the tag name. Here is the problem in code-speak:

#Include
#Include
$oXML=ObjCreate("Microsoft.XMLDOM")
$DirInput =@ScriptDir
$FileInput = "in-20120401.xml"
$sXmlFile =$DirInput & "\" & $FileInput
$oXML.load($sXmlFile)
$searchTerm="us-gaap:DeferredRevenueCurrent";
$XmlRootPath = "//"&$searchTerm
;
;LOOKING TO REPLICATE THIS RESULT USING CONTAINS FUNCTION:
;$searchTerm="us-gaap:DeferredRevenueCurrent";
;$XmlRootPath = "//"&$searchTerm
;dim $result2=$oXML.selectNodes($XmlRootPath)
;THE ABOVE WORKS ... BUT I CAN'T "FIND" IT USING CONTAINS as below
dim $result2=$oXML.selectNodes("//*[contains(.,'DeferredRevenueCurrent')]")
func _advancedQuery()
dim $xpathresult
For $xpathresult In $result2
ConsoleWrite($xpathresult.nodeName&@CRLF)
Next
EndFunc
_advancedQuery()

I am also attaching the XML file that I am using. Any help anyone could offer would be greatly appreciated.

in-20120401.xml

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

Thank you. That helps me understand what the query is doing (I am way off). Could you also help me understand what it should be? I am trying to find nodes that contain "DeferredRevenueCurrent" not nodes whose value is "DeferredRevenueCurrent" - does that make sense? I am trying to simulate this: "//us-gaap:DeferredRevenueCurrent" but looking based on just the term DeferredRevenueCurrent. Any additional help you could offer would be much appreciated.

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

I'm not aware of any wild card usage on the node name, except for .nodename...but that would require you grab the collection of all possible parents, and looping through each of their children.nodename, and do a string comaprison (like StringInStr)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

It's probably possible to do node-name searches with wild cards, i've just never needed to find a way :)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks. I can do it locally but I need to add a sleep to get it off the net - it can be extremely short: sleep(100) - but it won't work without that. I am also trying to test for "true" on return with a loop - but it seems to return true before it is ready to parse by the smallest fraction of a second ...

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...