ch3ft0ny Posted March 2, 2022 Share Posted March 2, 2022 arbitraryHello, i am trying to read some values from an XML File, but i cant get it to work Examle File: expandcollapse popup<?xml version="1.0" encoding="utf-8"?> <Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Tubes /> <Orders> <Order id="1" code="24676800_D"> <WorkOrders> <WorkOrder code="24676806_A" id="1"> <quantity>1</quantity> <deadlineTime>0001-01-01T00:00:00</deadlineTime> <PartPrograms> <PartProgram partCode="" id="1" path="\\server\BLM\PartProgram\24676806_A.bpf"> <macSerialNum>0782001120206</macSerialNum> <macCode /> <length>735</length> </PartProgram> </PartPrograms> </WorkOrder> <WorkOrder code="24676804_C" id="2"> <quantity>1</quantity> <deadlineTime>0001-01-01T00:00:00</deadlineTime> <PartPrograms> <PartProgram partCode="" id="1" path="\\server\BLM\PartProgram\24676804_C.bpf"> <macSerialNum>0782001120206</macSerialNum> <macCode /> <length>960.44800000000009</length> </PartProgram> </PartPrograms> </WorkOrder> <WorkOrder code="24676801_C" id="3"> <quantity>1</quantity> <deadlineTime>0001-01-01T00:00:00</deadlineTime> <PartPrograms> <PartProgram partCode="" id="1" path="\\server\BLM\PartProgram\24676801_C.bpf"> <macSerialNum>0782001120206</macSerialNum> <macCode /> <length>935</length> </PartProgram> </PartPrograms> </WorkOrder> <WorkOrder code="24604705_A" id="4"> <quantity>1</quantity> <deadlineTime>0001-01-01T00:00:00</deadlineTime> <PartPrograms> <PartProgram partCode="" id="1" path="\\server\BLM\PartProgram\24604705_A.bpf"> <macSerialNum>0782001120206</macSerialNum> <macCode /> <length>328.895</length> </PartProgram> </PartPrograms> </WorkOrder> </WorkOrders> <quantity>0</quantity> </Order> </Orders> </Data> There ist alwas just 1 "Order" node (but with an arbitrary "code=" value), and i need to read the "quantity" Value and from the "PartProgram" Node the "path=" value from every "WorkOrder" Node (which has always just 1 "PartProgram" Node) My current (test) code looks like this (i know this is wrong): $bixfile=FileOpenDialog("BIX File","\\SERVER\blm\ProTube\ProductionLists","bix (*.bix*)") Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load($bixfile) $oWorkOrders = $oXML.SelectNodes("//Data/Orders/Order") For $oWorkOrder In $oWorkOrders ConsoleWrite("$oWorkOrder.text=[" & $oWorkOrder.text & "]" & @CRLF) Next i have no clue how to do this. Maybe someone has an idea of how to do this. Thank you. Link to comment Share on other sites More sharing options...
Solution caramen Posted March 2, 2022 Solution Share Posted March 2, 2022 (edited) Hello, You could try to read help file about this command : StringInStr & _StringBetween You could use StringInStr to extract a string with one pattern. And re extract if needed. For post traitement with a second pattern Or _StringBetween to do it with two patterns directly with a function. exemple : #include <String.au3> _StringBetween ( $sString, $sStart, $sEnd [, $iMode = $STR_ENDISSTART [, $bCase = False]] ) ;======================= $myStringPat1 = "<WorkOrder code" $myStringPat2 = "</WorkOrder>" $bixfile="BIX File","\\SERVER\blm\ProTube\ProductionLists","bix (*.bix*)" $myWorkOrder = _ExportString ($myStringPat1,$myStringPat2,$bixfile) If IsArray($myWorkOrder) Then ConsoleWrite ("WorkOrder found !"&@CRLF) Else ConsoleWrite ("WorkOrder not found !"&@CRLF) EndIf Func _ExportString ($1,$2,$file) Local $String FileOpenDialog($file) If @error Then Return "Error openning the file" $String = _StringBetween($file, $1, $2 )[0] If @error Then Return "string not found or failure." Else Return $String EndIf EndFunc Edited March 2, 2022 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
ch3ft0ny Posted March 2, 2022 Author Share Posted March 2, 2022 Hello, Thank you for this quick solution. This is easier than the xml Functions and should do the job I will give it a try and report back. Link to comment Share on other sites More sharing options...
caramen Posted March 2, 2022 Share Posted March 2, 2022 But I'm not sure about the FileOpenDialog witch I never used. May a FileOpen & FileRead Then FileClose will be enougth. Not time to test. I'm sorry but I guess you got everything to get you done by yourself with that exemple My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
ch3ft0ny Posted March 2, 2022 Author Share Posted March 2, 2022 Hello, This did the Job for me: $bixfile=FileOpenDialog("BIX File","\\SERVER\blm\ProTube\ProductionLists","bix (*.bix*)") $bixcontent=FileRead ($bixfile) $WorkOrders=_StringBetween($bixcontent, "<WorkOrder code", "</WorkOrder>" ) $n_WO=UBound($WorkOrders) _ArrayDisplay($WorkOrders,"") Global $bix_qty[$n_WO], $bix_filename[$n_WO] for $i=0 to $n_WO-1 $bix_qty[$i]=_StringBetween($WorkOrders[$i],"<quantity>","</quantity>")[0] $bix_filename[$i]=StringRegExpReplace(_StringBetween($WorkOrders[$i],"path=""",""">")[0], "^.*\\", "") Next _ArrayDisplay($bix_qty,"") _ArrayDisplay($bix_filename,"") Again thank you very much Link to comment Share on other sites More sharing options...
caramen Posted March 2, 2022 Share Posted March 2, 2022 (edited) You have to be carefull. You should use array only with error checking or with uBound but after count the Ubound result to dodge script crashs Edited March 2, 2022 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
ch3ft0ny Posted March 2, 2022 Author Share Posted March 2, 2022 Ok, thanks for the tip Link to comment Share on other sites More sharing options...
Nine Posted March 2, 2022 Share Posted March 2, 2022 Here the XMLDom way to achieve what you want : #include <Constants.au3> Local $oTmp Local $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load("WorkOrder.xml") If $oXML.parseError.errorCode Then Exit MsgBox($MB_SYSTEMMODAL, "You have an error", $oXML.parseError.reason) $oWorkOrders = $oXML.SelectNodes("//Data/Orders/Order/WorkOrders/WorkOrder") For $oWorkOrder In $oWorkOrders ConsoleWrite("WorkOrder [" & $oWorkOrder.getAttribute("code") & "]") $oTmp = $oWorkOrder.SelectSingleNode("//quantity") ConsoleWrite(" has quatity of " & $oTmp.text) $oTmp = $oWorkOrder.SelectSingleNode("//PartPrograms/PartProgram") ConsoleWrite(" with the following path " & $oTmp.getAttribute("path") & @CRLF) Next Full documentation is here. “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...
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