gykisz Posted February 14, 2021 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
mikell Posted February 14, 2021 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
Nine Posted February 14, 2021 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
gykisz Posted February 14, 2021 Author 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?
Nine Posted February 14, 2021 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
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