bounty2k3 Posted March 19, 2015 Share Posted March 19, 2015 Hi guys, I have been trying to sort out this issue for a while. I've tried a bunch of different examples but none have worked. I have a rather large script at the moment so I will attempt to post the part I'm having issue with. I have an xml file I need to read from and get the line number of a certain string so I can use the stringmid function to get the account number on that line. So I need to find the line number of "<RogCustomerAcctNum>". Once I have that I can use Stringmid to get the 9 digit account number on that line. Any help would be greatly appreciated. There will be other line numbers I will need to get as well and hopefully with a little help on this one line will help me get the line number to the other numbers I need. Also, the "<RogCustomerAcctNum>" isn't always on the same line on that file. I need to set $accountline to the line number. Thanks in advance. Local $sFilePath3 = $SUITEFOLDER & $FOLDERCOUNT & "RecordData.xml" Local $hFileOpen1 = FileOpen($sFilePath3, $FO_READ) $sFileRead1 = FileReadLine($hFileOpen1, 2) $WORKORDER = StringMid($sFileRead1, 16, 13) $sFileRead2 = FileReadLine($hFileOpen1, 39) $AREA = StringMid($sFileRead2, 24, 3) $accountline = "" $sFileRead3 = FileReadLine($hFileOpen1, $accountline) $ACCOUNT = StringMid($sFileRead3, 29, 9) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted March 19, 2015 Moderators Share Posted March 19, 2015 How about reading the file to an array, and then parsing it. Think of this example, with a text file of computer names: #include <Array.au3> #include <File.au3> Local $sFile = @DesktopDir & "\PCs.txt" Local $aPCs _FileReadToArray($sFile, $aPCs) For $i = 1 To $aPCs[0] If StringInStr($aPCs[$i], "13325") Then ConsoleWrite($aPCs[$i] & " found on line " & $i & "." & @CRLF) Next "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 19, 2015 Moderators Share Posted March 19, 2015 bounty2k3,That sounds just the job for a RegEx - can you let us have a copy of the file (or at least a copy of the line on which "<RogCustomerAcctNum>" and the "9 digit account number" appear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bounty2k3 Posted March 19, 2015 Author Share Posted March 19, 2015 (edited) Posting a copy of the file. I have changed the name acct # and phone # as well as address to protect my clients personal info. where the #'s are there will be real numbers like 123456789. I have no experience with arrays per say, so I'm not sure I'd like to go that route. The file is deleted and moved after the work order is cleared from another program. So I have functions in place to find the file. When I first wrote the code it was before I found out that the account number gets written randomly. expandcollapse popup<Order> <OrderNumber>C239596621100</OrderNumber> <WorkOrderData> <WorkOrderNumber>C239596621100</WorkOrderNumber> <WorkOrderStateData> <CreatedAt>2015-03-17T21:05:37Z</CreatedAt> <ModifiedAt>2015-03-17T21:05:37Z</ModifiedAt> </WorkOrderStateData> </WorkOrderData> <OrderData> <BusinessRuleData> <IsSingleActivity>true</IsSingleActivity> <JobCode>NR</JobCode> <OrderCode>OC</OrderCode> <Priority>4</Priority> <PriorityLevel>4</PriorityLevel> <IsEmergency>false</IsEmergency> <BusinessUnit>SYD</BusinessUnit> <DispatchArea>SIMCOYRKDR</DispatchArea> <SchedulingArea>SIMCOYRKDR</SchedulingArea> <EarliestOnSiteAt>2015-03-17T22:05:00Z</EarliestOnSiteAt> <LatestOnSiteAt>2015-03-17T22:57:00Z</LatestOnSiteAt> <IsUndatedWork>false</IsUndatedWork> <WasCreatedByHost>true</WasCreatedByHost> <ExtSystemId>UCAD1-Rogers</ExtSystemId> <Address> <AddressLine1>123 Main St</AddressLine1> </Address> <CustomerContactPhone>705#######</CustomerContactPhone> <IsReceiptRequired>true</IsReceiptRequired> <IsOutOfCoverage>false</IsOutOfCoverage> <IsAutoDispatchable>false</IsAutoDispatchable> <IsClearedForDispatch>true</IsClearedForDispatch> <OrderClass>0</OrderClass> <HasAttachments>false</HasAttachments> </BusinessRuleData> <ExtendedData> <OrderRecord> <RogCompanyNum>239</RogCompanyNum> <RogStreetNum>0000123</RogStreetNum> <RogStreetName>MAIN</RogStreetName> <RogStreetType>ST</RogStreetType> <RogPostalCode>A1B2C3</RogPostalCode> <RogMunicCd>F72</RogMunicCd> <RogSubscriberName>NAME HERE</RogSubscriberName> <RogCustomerAcctNum>#########</RogCustomerAcctNum> <RogOrderType>TC</RogOrderType> <RogSHubId>152960</RogSHubId> <RogSMT>153111</RogSMT> <RogOrderCategory>SO</RogOrderCategory> <RogAtHomeInd>N</RogAtHomeInd> <RogReqCustPresence>Y</RogReqCustPresence> <RogTelInd>Y</RogTelInd> <RogPrimeDependCd>P</RogPrimeDependCd> <RogMapArea>AG1</RogMapArea> <RogPHub>POAL1</RogPHub> <RogSpecialInstr1>HAS 3 ADAPTERS BU 2 IN USE..ON NEVER WORKED..</RogSpecialInstr1> <RogSpecialInstr2>.ANOTHER DET SERV INT......</RogSpecialInstr2> <RogCableTypeCd>D6</RogCableTypeCd> <RogCableCondCd>H</RogCableCondCd> <RogDwellingCd>01</RogDwellingCd> <RogContractTypeCd>1A0</RogContractTypeCd> <RogFeedTypeCd>9</RogFeedTypeCd> <RogFranchiseAreaCd>BOR</RogFranchiseAreaCd> <MTAs> <RogMTASerial>203916062</RogMTASerial> <RogMTATouchInd>N</RogMTATouchInd> <MTAPhones> <RogMTAPhoneSeq>06</RogMTAPhoneSeq> <RogMTAPhoneNumber>705#######</RogMTAPhoneNumber> <RogMTAPhoneNative>N</RogMTAPhoneNative> <RogMTAPhoneStatus>ACTIVE</RogMTAPhoneStatus> <RogMTAPhoneVirtual>PRIME</RogMTAPhoneVirtual> <RogMTAPhonePort>01</RogMTAPhonePort> <RogMTAPhoneCMS>PROVIS</RogMTAPhoneCMS> </MTAPhones> </MTAs> <RogSuspendFlag>Y</RogSuspendFlag> <RogReferFlag>N</RogReferFlag> <RogReschedFlag>Y</RogReschedFlag> <RogCancelFlag>Y</RogCancelFlag> <RogOrderStatus>P</RogOrderStatus> <RogReschedueCount>00</RogReschedueCount> <RogAddrKeySeqNum>00001</RogAddrKeySeqNum> <RogEntryOperNum>7443</RogEntryOperNum> <RogOrderEntryDate>2015-03-12</RogOrderEntryDate> <RogOrderEntryTime>09:00:00-04:00</RogOrderEntryTime> <RogMunicName>ANGUS</RogMunicName> <RogConPhoneAreaCode>705</RogConPhoneAreaCode> <RogConPhoneNum>#######</RogConPhoneNum> <RogTelValid>Y</RogTelValid> <RogCBU>SYD</RogCBU> <RogHostOrderDue>2015-03-17T18:57:00-04:00</RogHostOrderDue> <RogHostAppointmentType>6P</RogHostAppointmentType> </OrderRecord> </ExtendedData> <OrderStateData> <OrderState>3</OrderState> <NominalDuration>47</NominalDuration> <RemainingDuration>47</RemainingDuration> <PercentComplete>0</PercentComplete> <CreatedAt>2015-03-17T21:05:37Z</CreatedAt> <DispatchedAt>2015-03-17T21:05:37Z</DispatchedAt> <CurrentAssignedMobileUserId>6081</CurrentAssignedMobileUserId> </OrderStateData> <OrderAssignmentData> <EstimatedTravelDuration>15</EstimatedTravelDuration> <EstimatedWorkDuration>47</EstimatedWorkDuration> <SlrRoutingData> <IsSlrRouted>false</IsSlrRouted> </SlrRoutingData> </OrderAssignmentData> </OrderData> </Order> Edited March 19, 2015 by Melba23 Added tags Link to comment Share on other sites More sharing options...
kylomas Posted March 19, 2015 Share Posted March 19, 2015 bounty2k3, This is not the line number but you can get the value of the node like this... $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.loadxml("<root>" & fileread(@scriptdir & '\xml.txt') & "</root>") $oACCTNUM = $oXML.SelectSingleNode('//RogCustomerAcctNum') ConsoleWrite($oACCTNUM.text & @CRLF) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 19, 2015 Moderators Share Posted March 19, 2015 bounty2k3,As I suggested, a RegEx is definitely the way to go here:expandcollapse popup; Simulate reading the file into a variable ; The real code would be ; $sString = FileRead("File_Path") $sString = "<Order>" & @CRLF & _ " <OrderNumber>C239596621100</OrderNumber>" & @CRLF & _ " <WorkOrderData>" & @CRLF & _ " <WorkOrderNumber>C239596621100</WorkOrderNumber>" & @CRLF & _ " <WorkOrderStateData>" & @CRLF & _ " <CreatedAt>2015-03-17T21:05:37Z</CreatedAt>" & @CRLF & _ " <ModifiedAt>2015-03-17T21:05:37Z</ModifiedAt>" & @CRLF & _ " </WorkOrderStateData>" & @CRLF & _ " </WorkOrderData>" & @CRLF & _ " <OrderData>" & @CRLF & _ " <BusinessRuleData>" & @CRLF & _ " <IsSingleActivity>true</IsSingleActivity>" & @CRLF & _ " <JobCode>NR</JobCode>" & @CRLF & _ " <OrderCode>OC</OrderCode>" & @CRLF & _ " <Priority>4</Priority>" & @CRLF & _ " <PriorityLevel>4</PriorityLevel>" & @CRLF & _ " <IsEmergency>false</IsEmergency>" & @CRLF & _ " <BusinessUnit>SYD</BusinessUnit>" & @CRLF & _ " <DispatchArea>SIMCOYRKDR</DispatchArea>" & @CRLF & _ " <SchedulingArea>SIMCOYRKDR</SchedulingArea>" & @CRLF & _ " <EarliestOnSiteAt>2015-03-17T22:05:00Z</EarliestOnSiteAt>" & @CRLF & _ " <LatestOnSiteAt>2015-03-17T22:57:00Z</LatestOnSiteAt>" & @CRLF & _ " <IsUndatedWork>false</IsUndatedWork>" & @CRLF & _ " <WasCreatedByHost>true</WasCreatedByHost>" & @CRLF & _ " <ExtSystemId>UCAD1-Rogers</ExtSystemId>" & @CRLF & _ " <Address>" & @CRLF & _ " <AddressLine1>123 Main St</AddressLine1>" & @CRLF & _ " </Address>" & @CRLF & _ " <CustomerContactPhone>705#######</CustomerContactPhone>" & @CRLF & _ " <IsReceiptRequired>true</IsReceiptRequired>" & @CRLF & _ " <IsOutOfCoverage>false</IsOutOfCoverage>" & @CRLF & _ " <IsAutoDispatchable>false</IsAutoDispatchable>" & @CRLF & _ " <IsClearedForDispatch>true</IsClearedForDispatch>" & @CRLF & _ " <OrderClass>0</OrderClass>" & @CRLF & _ " <HasAttachments>false</HasAttachments>" & @CRLF & _ " </BusinessRuleData>" & @CRLF & _ " <ExtendedData>" & @CRLF & _ " <OrderRecord>" & @CRLF & _ " <RogCompanyNum>239</RogCompanyNum>" & @CRLF & _ " <RogStreetNum>0000123</RogStreetNum>" & @CRLF & _ " <RogStreetName>MAIN</RogStreetName>" & @CRLF & _ " <RogStreetType>ST</RogStreetType>" & @CRLF & _ " <RogPostalCode>A1B2C3</RogPostalCode>" & @CRLF & _ " <RogMunicCd>F72</RogMunicCd>" & @CRLF & _ " <RogSubscriberName>NAME HERE</RogSubscriberName>" & @CRLF & _ " <RogCustomerAcctNum>123456789</RogCustomerAcctNum>" & @CRLF & _ " <RogOrderType>TC</RogOrderType>" & @CRLF & _ " <RogSHubId>152960</RogSHubId>" & @CRLF & _ " <RogSMT>153111</RogSMT>" & @CRLF & _ " <RogOrderCategory>SO</RogOrderCategory>" & @CRLF & _ " <RogAtHomeInd>N</RogAtHomeInd>" & @CRLF & _ " <RogReqCustPresence>Y</RogReqCustPresence>" & @CRLF & _ " <RogTelInd>Y</RogTelInd>" & @CRLF & _ " <RogPrimeDependCd>P</RogPrimeDependCd>" & @CRLF & _ " <RogMapArea>AG1</RogMapArea>" & @CRLF & _ " <RogPHub>POAL1</RogPHub>" & @CRLF & _ " <RogSpecialInstr1>HAS 3 ADAPTERS BU 2 IN USE..ON NEVER WORKED..</RogSpecialInstr1>" & @CRLF & _ " <RogSpecialInstr2>.ANOTHER DET SERV INT......</RogSpecialInstr2>" & @CRLF & _ " <RogCableTypeCd>D6</RogCableTypeCd>" & @CRLF & _ " <RogCableCondCd>H</RogCableCondCd>" & @CRLF & _ " <RogDwellingCd>01</RogDwellingCd>" & @CRLF & _ " <RogContractTypeCd>1A0</RogContractTypeCd>" & @CRLF & _ " <RogFeedTypeCd>9</RogFeedTypeCd>" & @CRLF & _ " <RogFranchiseAreaCd>BOR</RogFranchiseAreaCd>" & @CRLF & _ " <MTAs>" & @CRLF & _ " <RogMTASerial>203916062</RogMTASerial>" & @CRLF & _ " <RogMTATouchInd>N</RogMTATouchInd>" & @CRLF & _ " <MTAPhones>" & @CRLF & _ " <RogMTAPhoneSeq>06</RogMTAPhoneSeq>" & @CRLF & _ " <RogMTAPhoneNumber>705#######</RogMTAPhoneNumber>" & @CRLF & _ " <RogMTAPhoneNative>N</RogMTAPhoneNative>" & @CRLF & _ " <RogMTAPhoneStatus>ACTIVE</RogMTAPhoneStatus>" & @CRLF & _ " <RogMTAPhoneVirtual>PRIME</RogMTAPhoneVirtual>" & @CRLF & _ " <RogMTAPhonePort>01</RogMTAPhonePort>" & @CRLF & _ " <RogMTAPhoneCMS>PROVIS</RogMTAPhoneCMS>" & @CRLF & _ " </MTAPhones>" & @CRLF & _ " </MTAs>" & @CRLF & _ " <RogSuspendFlag>Y</RogSuspendFlag>" & @CRLF & _ " <RogReferFlag>N</RogReferFlag>" & @CRLF & _ " <RogReschedFlag>Y</RogReschedFlag>" & @CRLF & _ " <RogCancelFlag>Y</RogCancelFlag>" & @CRLF & _ " <RogOrderStatus>P</RogOrderStatus>" & @CRLF & _ " <RogReschedueCount>00</RogReschedueCount>" & @CRLF & _ " <RogAddrKeySeqNum>00001</RogAddrKeySeqNum>" & @CRLF & _ " <RogEntryOperNum>7443</RogEntryOperNum>" & @CRLF & _ " <RogOrderEntryDate>2015-03-12</RogOrderEntryDate>" & @CRLF & _ " <RogOrderEntryTime>09:00:00-04:00</RogOrderEntryTime>" & @CRLF & _ " <RogMunicName>ANGUS</RogMunicName>" & @CRLF & _ " <RogConPhoneAreaCode>705</RogConPhoneAreaCode>" & @CRLF & _ " <RogConPhoneNum>#######</RogConPhoneNum>" & @CRLF & _ " <RogTelValid>Y</RogTelValid>" & @CRLF & _ " <RogCBU>SYD</RogCBU>" & @CRLF & _ " <RogHostOrderDue>2015-03-17T18:57:00-04:00</RogHostOrderDue>" & @CRLF & _ " <RogHostAppointmentType>6P</RogHostAppointmentType>" & @CRLF & _ " </OrderRecord>" & @CRLF & _ " </ExtendedData>" & @CRLF & _ " <OrderStateData>" & @CRLF & _ " <OrderState>3</OrderState>" & @CRLF & _ " <NominalDuration>47</NominalDuration>" & @CRLF & _ " <RemainingDuration>47</RemainingDuration>" & @CRLF & _ " <PercentComplete>0</PercentComplete>" & @CRLF & _ " <CreatedAt>2015-03-17T21:05:37Z</CreatedAt>" & @CRLF & _ " <DispatchedAt>2015-03-17T21:05:37Z</DispatchedAt>" & @CRLF & _ " <CurrentAssignedMobileUserId>6081</CurrentAssignedMobileUserId>" & @CRLF & _ " </OrderStateData>" & @CRLF & _ " <OrderAssignmentData>" & @CRLF & _ " <EstimatedTravelDuration>15</EstimatedTravelDuration>" & @CRLF & _ " <EstimatedWorkDuration>47</EstimatedWorkDuration>" & @CRLF & _ " <SlrRoutingData>" & @CRLF & _ " <IsSlrRouted>false</IsSlrRouted>" & @CRLF & _ " </SlrRoutingData>" & @CRLF & _ " </OrderAssignmentData>" & @CRLF & _ " </OrderData>" & @CRLF & _ "</Order>" ; Now extract the account number $sExtract = StringRegExpReplace($sString, "(?s).*<RogCustomerAcctNum>(\d{9})</RogCustomerAcctNum>.*", "$1") ; And display it in the SciTE console ConsoleWrite($sExtract & @CRLF)The SRER looks for the bounding text and returns a string of exactly 9 digits it finds between them. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bounty2k3 Posted March 19, 2015 Author Share Posted March 19, 2015 (edited) I do appreciate the help. However the file doesn't always look that way. And is never in the same place twice. So, if I make the $sString read the xml file using fileread(), will that work with your extract? Forgot to mention that there are other calls throughout the script to reading the $account. And the account is forever changing as I complete a work order. So I believe that reading the same string over and over isn't going to help I'm afraid. I really need to read the file itself as it changes. Edited March 19, 2015 by bounty2k3 Link to comment Share on other sites More sharing options...
kylomas Posted March 19, 2015 Share Posted March 19, 2015 (edited) As long as the node name (RogCustomerAcctNum) does not change... edit: Incidentally, you can enumerate any node or value at any level using the XML DOM. Edited March 19, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 19, 2015 Moderators Share Posted March 19, 2015 (edited) bounty2k3,As kylomas has already said, as long as the number is bounded by that specific node it will be returned regardless of where it is in the file or whatever else there is on the other lines. That is the power of a RegEx - something very difficult to learn, but well worth the effort as this example of shows quite clearly. M23Edit:Just seen your edit. If you want to read the file whenever it changes, you will need to use something like seangriffin's FileSystemMonitor UDF to get notification that there is a change. Not that simple to use - do ask if you need any help. Edited March 19, 2015 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bounty2k3 Posted March 19, 2015 Author Share Posted March 19, 2015 Like I said, I really appreciate the help. The regexp works perfectly btw, I implemented it already. I just have to fix my script reads all of the area, workorder, address etc.... LOL but you guys have made life more simple. Thank you very much. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 19, 2015 Moderators Share Posted March 19, 2015 bounty2k3,really appreciate the helpThat is why we are here - glad we could provide an answer. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bounty2k3 Posted March 19, 2015 Author Share Posted March 19, 2015 One more quick question lol $ACCOUNT = StringRegExpReplace($RECORDDATAXML, "(?s).*<RogCustomerAcctNum>(d{9})</RogCustomerAcctNum>.*", "$1") the "9" in the middle of the code means 9 digits I'm guessing. and change that to however many digits I need like 3 or whatever. But what about for the address when the length always changes? can I use an asterisk *? $STREET = StringRegExpReplace($RECORDDATAXML, "(?s).*<RogStreetName>(d{*})</RogStreetName>.*", "$1") Link to comment Share on other sites More sharing options...
jdelaney Posted March 19, 2015 Share Posted March 19, 2015 (edited) bounty2k3, This is not the line number but you can get the value of the node like this... $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.loadxml("<root>" & fileread(@scriptdir & '\xml.txt') & "</root>") $oACCTNUM = $oXML.SelectSingleNode('//RogCustomerAcctNum') ConsoleWrite($oACCTNUM.text & @CRLF) kylomas This is the easiest route to go for XML...this object is made exactly for moving through .xml files... There is no need to include the '<root>' in it, since it's already valid xml... $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load(@scriptdir & '\xml.txt') $oACCTNUM = $oXML.SelectSingleNode('//RogCustomerAcctNum') ConsoleWrite($oACCTNUM.text & @CRLF) edit: to include your new node: $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load(@scriptdir & '\xml.txt') $oACCTNUM = $oXML.SelectSingleNode('//RogCustomerAcctNum') $oStreetName = $oXML.SelectSingleNode('//RogStreetName') ConsoleWrite($oACCTNUM.text & @CRLF) ConsoleWrite($oStreetName.text & @CRLF) edit2: to specifically answer your question, the d means it will ONLY grab digits...0-9...that will not work with alpha numeric nodes. Edited March 19, 2015 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...
Moderators Melba23 Posted March 19, 2015 Moderators Share Posted March 19, 2015 (edited) bounty2k3,You can use (.*) which means any number of characters of any sort. M23 Edited March 19, 2015 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bounty2k3 Posted March 19, 2015 Author Share Posted March 19, 2015 I have tried. Local $sFilePath3 = $SUITEFOLDER & $FOLDERCOUNT & "\RecordData.xml" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load(FileRead($sFilePath3)) $ACCOUNT = $oXML.SelectSingleNode('//RogCustomerAcctNum') $STREET = $oXML.SelectSingleNode('//RogStreetName') $NAME = $oXML.SelectSingleNode('//RogSubscriberName') and also tried.... Local $sFilePath3 = $SUITEFOLDER & $FOLDERCOUNT & "\RecordData.xml" $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load($sFilePath3) $ACCOUNT = $oXML.SelectSingleNode('//RogCustomerAcctNum') $STREET = $oXML.SelectSingleNode('//RogStreetName') $NAME = $oXML.SelectSingleNode('//RogSubscriberName') But my script is not reading them. I was able to use regexp for the account number. And tried {.*} where {9} is to get the street name. But to avail. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 19, 2015 Moderators Share Posted March 19, 2015 bounty2k3,Sorry - a typo on my part in the post above which I have now corrected (I used curly brackets instead of smooth ones - I blame the lateness of the hour). You need to do this:$sExtract = StringRegExpReplace($RECORDDATAXML, "(?s).*<RogNode>(.*)</RogNode>.*", "$1")That will collect whatever is between the 2 nodes. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bounty2k3 Posted March 19, 2015 Author Share Posted March 19, 2015 No problem. It gets late everywhere at some point That one works. As a side note. (d{.*}) copied the entire contents of the file. Link to comment Share on other sites More sharing options...
jdelaney Posted March 19, 2015 Share Posted March 19, 2015 (edited) Add some debugging: Local $sFilePath3 = $SUITEFOLDER & $FOLDERCOUNT & "\RecordData.xml" If FileExists($sFilePath3) Then ConsoleWrite("found file" & @CRLF) Else ConsoleWrite("file not found" & @CRLF) exit 1 EndIf $oXML = ObjCreate("Microsoft.XMLDOM") $oXML.load($sFilePath3) If StringLen($oXML.xml) Then ConsoleWrite("loaded xml" & @CRLF) Else ConsoleWrite("xml not loaded" & @CRLF) exit 1 EndIf $oACCTNUM = $oXML.SelectSingleNode('//RogCustomerAcctNum') $oStreetName = $oXML.SelectSingleNode('//RogStreetName') ConsoleWrite($oACCTNUM.text & @CRLF) ConsoleWrite($oStreetName.text & @CRLF) note: I grabbed your entire contents into a file, and the script works fine. Edited March 19, 2015 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...
guinness Posted March 19, 2015 Share Posted March 19, 2015 Just as a reminder for those who use _FileReadToArray(), FileReadToArray() now exists. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
bounty2k3 Posted September 4, 2015 Author Share Posted September 4, 2015 Hi guys, I'm back to reopen this topic. All of the info you have given me has been working for the most part. I really did appreciate the help.I currently have two issues with regexp. It's been a couple months of testing, tweaking, hair pulling, smashing my head on the keyboard, but I haven't been able to figure it out.Issue #1 In the coding you helped me with, is there a fail safe that if the node doesn't appear in the file that it does nothing? Like, If not stringexists? The problem I have is that if the node doesn't exist, it actually copies the entire file. Issue #2In another file I'm working in 1 particular node will appear numerous times. When using the regexp it is only grabbing the last instance of the node in the file. Is there a way to copy each individual instance? Sometimes the node will appear once, sometimes 5 times, sometimes 10, or not at all. Basically, I want to copy each serial number to a line in a text file, and later in the script (which is not to worry about right now), I will call those serials from the text file. As you can see, I've been trying, and messing around with it, but I can't figure it out. The info on regexp has my brain confused. Thank you in advance,Bounty2k3Func GETSERIALS() Local $TEMPSERIALFILE = $INSTALLDIR & "TempSerials.txt" If Not FileExists($TEMPSERIALFILE) Then FileWrite($TEMPSERIALFILE, "") EndIf If $ORDERTYPE = "WO" Then Local $GETSERIALS = $SUITEFOLDER & "\" & $FOLDERCOUNT & "\Activities\1\UpdateForms\1\RecordData.xml" Local $GETSERIALS1 = FileOpen($GETSERIALS, $FO_READ) Local $GETSERIALS2 = FileRead($GETSERIALS1) $SERIAL1 = StringRegExpReplace($GETSERIALS2, "(?s).*<RogEquipSerialNum HasChanged=""0"">(.*)</RogEquipSerialNum>.*", "${1}") $SERIAL2 = StringRegExpReplace($GETSERIALS2, "(?s).*<RogEquipSerialNum HasChanged=""0"">(.*)</RogEquipSerialNum>.*", "${0}") FileClose($GETSERIALS1) _FileWriteToLine($TEMPSERIALFILE, 1, $SERIAL1, True) _FileWriteToLine($TEMPSERIALFILE, 2, $SERIAL2, True) EndIf EndFunc 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