Jump to content
Sign in to follow this  
h3ir

simple XML Reader

Recommended Posts

h3ir

Have a look at this:

It will read a simple XML Structure and Output it as Array and write additional the parsed XML in a Log-File...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.12.0
 Author:         h3ir

 Script Function:
    Easy XML Parser
    
 XML Example:
<Path>
 <Point>
     <Description>#1</Description>
     <X>120</X>
     <Y>300</Y>
 </Point>
 <Point>
     <Description>#2</Description>
     <X>150</X>
     <Y>250</Y>
 </Point>
</Path>

#ce ----------------------------------------------------------------------------

#include-once

Func __ParseXML($XMLfile)
    
    FileDelete(@ScriptDir & "\parse.log")

    $file = FileOpen($XMLfile, 0)

    $i = 0
    $j = 0

    While 1
        
        $i = $i+1
        $line = FileReadLine($file, $i)
        $line = StringReplace($line, " ", "")
        $line = StringReplace($line, @tab, "")
        
        If $line == "<Point>" Then
            $j = $j+1
        EndIf
        
        If $line == "</Path>" Then
            ExitLoop
        EndIf
        
    WEnd

    Dim $Path[$j][3]

    $Point = 0
    $i = 0
    $j = -1

    While 1
        
        $i = $i+1
        $line = FileReadLine($file, $i)
        $line = StringReplace($line, " ", "")
        $line = StringReplace($line, @tab, "")
        
        If $line == "<Point>" Then
            $Point = 1
            $j = $j+1
        EndIf
        
        If $Point == 1 AND StringLeft($line,13)='<Description>' then
            $trim = StringTrimLeft($line,StringInstr($line,'<Description>')+12)
            $Path[$j][0] = StringTrimRight($trim,14)
        EndIf

        If $Point == 1 AND StringLeft($line,3)='<X>' then
            $trim = StringTrimLeft($line,StringInstr($line,'<X>')+2)
            $Path[$j][1] = StringTrimRight($trim,4)
        EndIf

        If $Point == 1 AND StringLeft($line,3)='<Y>' then
            $trim = StringTrimLeft($line,StringInstr($line,'<Y>')+2)
            $Path[$j][2] = StringTrimRight($trim,4)
        EndIf

        If $Point == 1 AND $line == "</Point>" Then
            $Point = 0
        EndIf
        
        If $Point == 0 AND $line == "</Path>" Then
            ExitLoop
        EndIf

    WEnd

    $maxArray = Ubound($Path)

    $i = 0
    While $i <= $maxArray-1
        $log = FileOpen(@ScriptDir & "\parse.log",1)
        FileWriteLine($log, $Path[$i][0]&@tab&$Path[$i][1]&@tab&$Path[$i][2])
        FileClose($log)
        $i = $i+1
    WEnd

    Return $Path

EndFunc

Share this post


Link to post
Share on other sites
darzanmihai

Could you create a XML file with Autoit Script??


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
Andreik

Could you create a XML file with Autoit Script??

Yes.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
h3ir

Could you create a XML file with Autoit Script??

I will create a example script for this later...

Share this post


Link to post
Share on other sites
darzanmihai

I will create a example script for this later...

I am verry interested about creating an XML file.


I do not like stupid and idiot people that write idiot things...If you are one, do not write.

Share this post


Link to post
Share on other sites
darzanmihai

Yes.

I knew that it could be done, but I wos wondering if h3ir could make a script example. muttley

I do not like stupid and idiot people that write idiot things...If you are one, do not write.

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
Sign in to follow this  

×