gykisz Posted February 14, 2021 Share Posted February 14, 2021 Hi Guys, I would need the value of i4 from the attached xml file, but the selectSingleNode doesn't work for me. Help, pls. #include <Array.au3> Enum $iData_NodeName, $iData_AttributeName, $iData_AttributeValue, $iData_UBound $oXML = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oXML) Then MsgBox(0, "", "Unable to create COM session to XML.") Exit EndIf $oXML.Load(@ScriptDir & "\teszt.xml") $oParent = $oXML.selectSingleNode('//methodResponse/params/param/value/struct/member[name =""Id""]/value/i4') $aData = "" $i = 0 For $oChild In $oParent.childNodes For $oAttribute In $oChild.attributes If IsArray($aData) Then ReDim $aData[UBound($aData) + 1][$iData_UBound] Else Local $aData[1][$iData_UBound] EndIf $aData[UBound($aData) - 1][$iData_NodeName] = $oChild.nodename $aData[UBound($aData) - 1][$iData_AttributeName] = $oAttribute.nodename $aData[UBound($aData) - 1][$iData_AttributeValue] = $oAttribute.text ConsoleWrite("NodeName=[" & $oChild.nodename & "]: AttributeName=[" & $oAttribute.nodename & "] AttributeValue=[" & $oAttribute.text & "]" & @CRLF) Next $i += 1 Next _ArrayDisplay($aData, $i) teszt.xml Link to comment Share on other sites More sharing options...
mikell Posted February 14, 2021 Share Posted February 14, 2021 (edited) Alternative way... for such a simple request it could be done like this Msgbox(0,"", StringRegExp(FileRead("teszt.xml"), '<i4>([^<]+)', 1)[0] ) Edited February 14, 2021 by mikell typo Link to comment Share on other sites More sharing options...
Nine Posted February 14, 2021 Share Posted February 14, 2021 (edited) Try this : $oXML = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oXML) Then Exit MsgBox(0, "", "Unable to create COM session to XML.") $oXML.Load("teszt.xml") $oParent = $oXML.selectSingleNode('//struct/member[name="id"]/value/i4') MsgBox ($MB_SYSTEMMODAL, "", $oParent.text) Edited February 14, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gykisz Posted February 14, 2021 Author Share Posted February 14, 2021 Thank you, guys! Both solutions work great. Just another question, @Nine. This xml file is a result of an http query, but if I use it this way: $oXML.Load = $XmlHttp.responsetext, then it doesn't work. What could be the reason for this? Link to comment Share on other sites More sharing options...
Nine Posted February 14, 2021 Share Posted February 14, 2021 The .load method is getting a file. To load a string you must use .loadXML method instead : $oXML.loadXML($sXML) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gykisz Posted February 16, 2021 Author Share Posted February 16, 2021 Thanks, it works great. 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