Jump to content

XML writing and reading using external exe


WolfWorld
 Share

Recommended Posts

If you think that this is a virus then use the Autoit XML UDF. Just don't complain.

okay lets start.

Multi-Thread alike. This mean that your application does not need to write to the file. So no waiting.

Native code speed, when is Autoit going to support XML natively?

Easy syntax. Even beginner can start using it.

Anything else you want to know just ask. AND YES IT'S NOT A VIRUS.

#include <Constants.au3>

;Remeber I used Streaming API to do all of this to keep it simple for all of you.
;But if I get great response I will make a DOM version of it also and I will try to make it simple.

Local $foo = Run("XMLExtensionForAutoit.exe", @ScriptDir, @SW_HIDE, $STDIN_CHILD)
;!!! Remeber No "Space" or "anything you can't use in a Autoit variable include $" unless it's a value. A value is the second text you send after the ":X:X:" or " ":X:" command.
;All of this is NOT self manage therefor if you make an error the program will hang.
;You can open as many, reads and writes at the same time but not on the same file.
StdinWrite($foo, "write" & @CRLF);There is a read and write mode. I will show you the read mode later on.
StdinWrite($foo, "test.txt" & @CRLF);It will create a file. Remember that this does not update but it creates a new "blank" file.
StdinWrite($foo, ":start:element:" & @CRLF);Call the Start Element stream.
StdinWrite($foo, "MyFirstElementSpan" & @CRLF);Input in to the stream.
;for $i = 1 to 20000 ; if you want to see how fast it is.
StdinWrite($foo, ":element:" & @CRLF);This time call Element(Value) stream.
StdinWrite($foo, "MyFirstElement" & @CRLF);The name.
StdinWrite($foo, "Now can now have space in the value section!" & @CRLF);The Value.
StdinWrite($foo, ":element:" & @CRLF);Another one
StdinWrite($foo, "MySecondElement" & @CRLF);And so on...
StdinWrite($foo, "MySecond Value" & @CRLF)
StdinWrite($foo, ":start:element:" & @CRLF);Now this create another layer.
StdinWrite($foo, "SpanInsideASpan" & @CRLF)
StdinWrite($foo, ":element:" & @CRLF)
StdinWrite($foo, "What" & @CRLF)
StdinWrite($foo, "It is so cool dude!" & @CRLF)
StdinWrite($foo, ":end:element:" & @CRLF);Close the second layer "</SpanInsideASpan>"
StdinWrite($foo, ":element:" & @CRLF);Write on the first span.
StdinWrite($foo, "LeftOver" & @CRLF)
StdinWrite($foo, "Wow It Just Work" & @CRLF)
;next
StdinWrite($foo, ":end:element:" & @CRLF);End the first.
StdinWrite($foo, ":end:" & @CRLF);Remember to write this to "flush" and "end" or else the program will just idle with a "blank" file.

Sleep(1000);Wait for the handle to close, on up-to-date computer it only takes about 10 but just to make sure because if the handle is not release it will result in a crash
;Now we are going to read from the test.txt we just wrote.

Local $bar = Run("XMLExtensionForAutoit.exe", @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($bar, "read" & @CRLF)
StdinWrite($bar, "test.txt" & @CRLF)
StdinWrite($bar, "MyFirstElement" & @CRLF)
StdinWrite($bar, "LeftOver" & @CRLF)
StdinWrite($bar, ":end:" & @CRLF)

Local $data
While True
    $data &= StdoutRead($bar);Yes, It took me about a hour to figure that it need to be $bar and not $foo
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Read Search", $data)

XMLExtensionForAutoit.exe

Edited by athiwatc
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...