Jump to content

StringInStr and tags


Recommended Posts

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
Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

×
×
  • Create New...