Jump to content
LoneWolf_2106

StringInStr and tags

Recommended Posts

LoneWolf_2106

Hi everybody,

i have a log file with several entries like the following one:

INFO [26.04.2017 11:37:48] [main] XML-Data: 
<online-activation>

  <general>
    <userid>XYZ</userid>
    <mac-address/>
    <OU>VG-DE</OU>
    <ROLE>KDT</ROLE>
    <FOA>PRO;FC;DOM;MDD</FOA>
    <BRD>XYZ;IMP</BRD>
  </general>

  <applications>
    <app expiration-date="2017-10-01" name="BB-INFO"/>
    <app expiration-date="2017-10-01" name="MMSKD"/>
    <app expiration-date="2017-10-01" name="FM-TOOL"/>
    <app expiration-date="2017-04-05" name="WEB-BTD"/>
    <app expiration-date="2017-10-01" name="OFFLINE-BTD"/>
    <app expiration-date="2017-10-01" name="MDU-UPD"/>
    <app expiration-date="2017-10-01" name="MDU"/>
    <app expiration-date="2017-04-05" name="WEB-WDA"/>
    <app expiration-date="2017-04-05" name="WEB-ETD"/>
    <app expiration-date="2017-10-01" name="OFFLINE-WDA"/>
    <app expiration-date="2017-10-01" name="OFFLINE-ETD"/>
  </applications>

</online-activation>

 

I need to collect all the XML-Data, my search doesn't work:

 

Func FileSearch()
    $j=0
    For $i = 0 To UBound($content_array) - 1
            $search_result=StringInStr($content_array[$i],$search)

                If $search_result<>0 Then
                    ReDim $searchResultArray[UBound($searchResultArray) + 1]
                    $searchResultArray [$j] = $content_array[$i]
                    _ArrayDisplay($searchResultArray)
                $j+=1
                EndIf

    Next
EndFunc

If i search for "online-activation", it retrieves only the first and the last tag, but not what is within.

In addition, when i use FileReadToArray, all the entries between <online-activation> and </online-activation>

2017-07-03 14_22_55-ArrayDisplay.png

Edited by LoneWolf_2106

Share this post


Link to post
Share on other sites
water

In the User Defined Functions reference of the wiki you will find a few XML-related UDFs.
Maybe they can better handle your log file format.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
LoneWolf_2106

Hi Water,

thanks for your support, i looked for a function in https://www.autoitscript.com/autoit3/docs/libfunctions.htm, but i didn't find any function related to XML. Maybe i am looking in the wrong document.

 

In Addition i have modified my function, but it writes only an entry, every time starts writing a new row, the previous one "disappear":

 

Func FileSearch($sStringToSearch)
    $k=0
    $count_search=0
    For $count = 0 To UBound($content_array) - 1
            $search_result=StringInStr($content_array[$count],$sStringToSearch)
                If $search_result<>0  Then
                    $count_search+=1
                    ReDim $SearchOnlineActivation[$count_search][$k] ;Adding a row
                    ;MsgBox($MB_OK, "rows", UBound($SearchOnlineActivation, $UBOUND_ROWS))
                    For $k=0 To 48
                        $k+=1
                        ReDim $SearchOnlineActivation[$count_search][$k] ;Adding a column
                        $count+=1
                        $SearchOnlineActivation [$count_search -1][$k-1] = $content_array[$count]
                        ;_ArrayDisplay($SearchOnlineActivation)
                        Next
                EndIf
    Next
    _ArrayDisplay($SearchOnlineActivation)
EndFunc

 

Edited by LoneWolf_2106

Share this post


Link to post
Share on other sites
water

If you carefully read my last post you will notice that I was talking about the wiki. There you will find some XML related UDFs.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
LoneWolf_2106

Thanks Water, i was reading at the wrong place, i've stored the Webpage. Anyway i've noticed that the library works if i have a real XML file. Unfortunately i have just an extract of some tags from a XML document, i have just some tags in a text logfile, which is not a XML file.

Edited by LoneWolf_2106

Share this post


Link to post
Share on other sites
LoneWolf_2106

Hi,

 

can anyone try my function and tell me why the previous search disappears from the array?

 

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <File.au3>
#include <Array.au3>


;Variables definition

$search = "XML-Daten"
$file=@ScriptDir & "\test.log"

Global $SearchOnlineActivation[0][0]


;Program execution

FileReading()
FileSearch($search)

;File read

Func FileReading()

Global $content_array = FileReadToArray($file)
_ArrayDisplay($content_array)


If @error Then
        MsgBox($MB_OK, "", "There was an error reading the file. @error: " & @error)
;   Else
 ;     For $i = 0 To UBound($content_array) - 1
 ;        MsgBox($MB_OK, "", $content_array[$i])
  ;      Next
    EndIf
EndFunc


;File search with XML tags

 Func FileSearch($sStringToSearch)
    $k=0
    $count_search=0
    For $count = 0 To UBound($content_array) - 1
        $search_result=StringInStr($content_array[$count],$sStringToSearch)
                If $search_result<>0  Then
                    $count_search+=1
                    ReDim $SearchOnlineActivation[$count_search][$k] ;Adding a row
                    For $k=0 To 53
                        $k+=1
                        ReDim $SearchOnlineActivation[$count_search][$k] ;Adding a column
                        $SearchOnlineActivation [$count_search -1][$k-1] = $content_array[$count]
                        $count+=1
                        ;_ArrayDisplay($SearchOnlineActivation)
                    Next
                EndIf
    Next
    _ArrayDisplay($SearchOnlineActivation)
EndFunc


;File close

FileClose ("$file")

 

test.log

Share this post


Link to post
Share on other sites
water

Maybe I'm wrong (haven't worked with XML so far) but I would create a "real" XML file by reading the file, dropping all non-XML lines and then use a XML UDF to process the created XML file.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • OneSolution
      By OneSolution
      Hi guys! I have these checkbox that I'm trying to click on. They have the same inner-text string but a different ID. Sometime there can be as many as 4 checkbox
      with the same string but the ID is always different. I tried a few methods down below but I'm unable to make any real results. Any suggestions or solutions I would
      appreciate it very much.
      <ul><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-2"><!-- react-text: 675 -->Morning<!-- /react-text --><!-- react-text: 676 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 678 -->OTHER<!-- /react-text --><!-- react-text: 679 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 681 -->8:30 AM<!-- /react-text --><!-- react-text: 682 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 684 -->10:30 AM<!-- /react-text --><!-- react-text: 685 -->&nbsp;<!-- /react-text -- ></div><div class="cx-item-contents col-md-1"><!-- react-text: 687 -->SRV<!-- /react-text --><!-- react-text: 688 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox1" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox1"></label></div></div></div></li><li class="cx-list-item-wrapper" data-day="Aug 2 2018 07:27:37 GMT-0700 (Pacific Daylight Time)"><div class=""><div class="cx-list-item-container"><div class="cx-list-item cx-item-icon-2 pointer-cursor"><div class="cx-item-contents cx-item-time col-md-1"><!-- react-text: 698 -- >Morning<!-- /react-text --><!-- react-text: 699 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 701 -->OTHER<!-- /react- text --><!-- react-text: 702 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 704 -->8:30 AM<!-- /react-text --><!-- react-text: 705 -->&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-2"><!-- react-text: 707 -->2:30 PM<!-- /react-text --><!-- react-text: 708 -- >&nbsp;<!-- /react-text --></div><div class="cx-item-contents col-md-1"><!-- react-text: 710 -->SRV<!-- /react-text --><!-- react-text: 711 -->&nbsp;<!-- /react-text --></div></div></div><div class="pull-right cx-listitem-chk"><div><input id="cx_checkbox2" class="cx-fa-chk cx-selfschedule-chk" value="on" type="checkbox"><label for="cx_checkbox2"></label></div></div></div></li></ul> I tried the _IETagNameGetCollection() but it only check the box but doesn't fire the event! And I'm unable to submit that without a click action.
      Func _Box1() $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id == "cx_checkbox1" Then $oInput.checked = true Next Sleep(10) ToolTip('box1') EndFunc ;==>_Box1 I also tried click by text.The boxes do get check by a click but the problem with that is it will select every box that has the same string. I'm allowed only to check 1 box selection at a time per day for the submit button to work.  Any preference to select only the second box and bypass the other?
      Func _Morning() For $a In _IETagNameGetCollection($oIE, "div") If StringInStr(_IEPropertyGet($a, "innerText"), "Morning") Then _IEAction($a, "click") EndIf Next Sleep(10) ToolTip('Morning selected') EndFunc ;==>Morning The last method I tried was _IEGetObjById(). It doesn't click or respond to the checkbox.
      Func _Click1() $oChk = _IEGetObjById($oIE, "cx_checkbox1") _IEAction($oChk, 'click') Sleep(20) ToolTip('box1') EndFunc ;==>_Click1  
    • DynamicRookie
      By DynamicRookie
      Hey there!
       
      I've been developing a artificial intelligence.

      My first hard task was letting the A.I know when a sentence is found in memory with different words
      What i tried to do here is simply, get all the words in user sentence that could be used
      as a identifier
              
              example: Steve Jobs
              
              then identify the sentence purpose with the words we found in the past "for" loop
              
              example: Do/Know/You/Who/Steve/Jobs
              
              Compare the example in the following matching sentences in memory.
              
              1-Steve jobs was a known person
              2-Do you know who barack obama is?
              3-Do you know Steve jobs?
              4-Do you know who steve jobs is?
              5-How much money steve jobs had
              
              Then find the sentence that has way more matches than the other ones, remember that if the identifier words were not found
              (Steve jobs) then the sentence is invalid.
              
              Every sentence has a different answer and is important that the right one is chosen.
              
      If there's no more than the half of words in matches, then assign a variable the result of function, such as a return but for a global var.
      I couldn't figure out how to do that with StringRegExp.
       
      I honestly need help with detecting identifiers on memory sentences.
      I would also like to let the AI know typos, meaning that moeny and money means the same thing.
      Any help is hugely appreciated.

       
    • MrSparty1995
      By MrSparty1995
      I have a good handle on how to read a file line by line, and search for a given string.
      Basically using, FileOpen, FileReadLine, and StringInStr.
      I have been trying to figure out why my search keeps coming back with no match.
      For example, if my string line was "Where is Waldy", and I was searching for Waldy that comes back fine.
      But in my file, Let's say it is
      Where is "Waldy"
      So i read that line in and do a search for Waldy, but i comes back with no match since there is quotes around it.
      Is there a way to resolve this?
      Here is my actual example
      The line comes back like this
          <JposEntry logicalName="LineDisp_iSC480">
      I'm searching for LineDisp_iSC480, but its coming back with no match due to the quotes.
      Thanks in advance, James
    • AliOzturk
      By AliOzturk
      Hello, I want to be able to search for multiple strings and if any of the strings are found I want it returned which one it is. I've been able to search for multiple strings using the OR command, but I'm not sure how I am supposed to make it return which of my strings is found. I've given an example below
      If StringInStr($html, Batman) OR StringInStr($html, Superman) Then MsgBox(0, "Success", "The string found was: Superman") EndIf So it will search for the two strings and whichever it founds it will return me with. How can I make that work?
    • rootx
      By rootx
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> Local $path="C:\Users\rootx\Desktop\Nuova cartella",$mask = "*.jpg;*.png;*.ico",$Pos $FileArr = _FileListToArrayRec($path,$mask,1,1,1,2) For $x = 1 to UBound($FileArr)-1 If $Pos = StringInStr($FileArr[$x],"-") Then ConsoleWrite("------"&$FileArr[$x]&@CRLF) Else ConsoleWrite($FileArr[$x]&@CRLF) FileDelete($FileArr[$x]) EndIf ConsoleWrite($x&@CRLF) Next ConsoleWrite($x-1&@CRLF) I would write a loop that individuals and delete files that contain this feature....
      File name-150x100.jpg, or other -SizexSize
      But in this case how can I filter properly?
      File name 150x100-150x100.jpg
      File name -100-150x100.jpg
       
×