Jfish Posted March 19, 2013 Share Posted March 19, 2013 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 More sharing options...
jdelaney Posted March 19, 2013 Share Posted March 19, 2013 Right now, you are looking for a node like this <*>DeferredRevenueCurrent</*> 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 More sharing options...
Jfish Posted March 19, 2013 Author Share Posted March 19, 2013 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 More sharing options...
jdelaney Posted March 19, 2013 Share Posted March 19, 2013 (edited) 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 March 19, 2013 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 More sharing options...
Jfish Posted March 19, 2013 Author Share Posted March 19, 2013 So you always need to know the node names before you search unless you do as you suggest .... bummer. Thanks for the help. I really appreciate it. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
jdelaney Posted March 19, 2013 Share Posted March 19, 2013 (edited) It's probably possible to do node-name searches with wild cards, i've just never needed to find a way Edited March 19, 2013 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 More sharing options...
Jfish Posted March 19, 2013 Author Share Posted March 19, 2013 Actually the stringinstr worked pretty well - it was very fast. if StringInStr($xpathresult.nodeName,"DeferredRevenue",1)<>0 then ConsoleWrite($xpathresult.nodeName&@CRLF) Thanks again for your help. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Jfish Posted March 19, 2013 Author Share Posted March 19, 2013 @jdelaney - I have one more question for you. Is there a way to loadwait an XML doc? In other words, can I wait for this to finish somehow: $oXML.load($interactiveFilingURL)? Thanks for any help you can offer. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
jdelaney Posted March 19, 2013 Share Posted March 19, 2013 Not sure. I'd save the XML to a file, and use .loadxml or, get the xml text, and use that in .load 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 More sharing options...
Jfish Posted March 19, 2013 Author Share Posted March 19, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now