Jump to content
Sign in to follow this  
Tiger

Create XML file

Recommended Posts

Tiger

I would like to create a xml file.

This is the xml file.

<Experience>
    <tasks>
        <task id="{9E84D66F-96BA-41b5-B20B-0624CF565F6D}" xmlns="http://schemas.microsoft.com/windows/tasks/v1">
            <name>Test1</name>
        </task>
        <task id="{1D8650FD-8935-4657-A3E3-C6AD82DCFEB8}" xmlns="http://schemas.microsoft.com/windows/tasks/v1">
            <name>Test2</name>
        </task>
    </tasks>
</Experience>
Edited by Tiger

My UDFs:- _RegEnumKey

Share this post


Link to post
Share on other sites
ofLight

One Way

$file = FileOpen("Experience.xml",2)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file,'<Experience>'&@CRLF& _
                '<tasks>'&@CRLF& _
                '<task id="{9E84D66F-96BA-41b5-B20B-0624CF565F6D}" xmlns="http://schemas.microsoft.com/windows/tasks/v1">'&@CRLF& _
                '<name>Test1</name>'&@CRLF& _
                '</task>'&@CRLF& _
                '<task id="{1D8650FD-8935-4657-A3E3-C6AD82DCFEB8}" xmlns="http://schemas.microsoft.com/windows/tasks/v1">'&@CRLF& _
                '<name>Test2</name>'&@CRLF& _
                '</task>'&@CRLF& _
                '</tasks>'&@CRLF& _
                '</Experience>')



FileClose($file)

But I would Recomment looking up ElTorros XML Function, much better way

Link

Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites
weaponx

#include "_XMLDomWrapper.au3"

Const $FileName = "out.xml"
Const $XMLNS = "http://schemas.microsoft.com/windows/tasks/v1"

Dim $Keys[2] =  ["id","xmlns"]
Dim $Values[2]

;Create file (force overwrite existing file)
$result = _XMLCreateFile($FileName, "Experience", 1)

Switch @error
    Case 0 
        ConsoleWrite("No error" & @CRLF)
    Case 1 
        ConsoleWrite("Failed to create file" & @CRLF)
    Case 2 
        ConsoleWrite("No object" & @CRLF)
    Case 3 
        ConsoleWrite("File creation failed MSXML error" & @CRLF)
    Case 4 
        ConsoleWrite("File exists" & @CRLF)
EndSwitch

;Open created file
_XMLFileOpen($FileName)

_XMLCreateRootChild ("tasks", "")

;Create task 1
$Values[0] = "{9E84D66F-96BA-41b5-B20B-0624CF565F6D}"
$Values[1] = $XMLNS
_XMLCreateChildWAttr ("//tasks", "task", $Keys, $Values)
_XMLCreateChildNode ("//tasks/task[1]", "name", "Test1", "")

;Create task 2
$Values[0] = "{1D8650FD-8935-4657-A3E3-C6AD82DCFEB8}"
$Values[1] = $XMLNS
_XMLCreateChildWAttr ("//tasks", "task", $Keys, $Values)
_XMLCreateChildNode ("//tasks/task[2]", "name", "Test2", "")

Share this post


Link to post
Share on other sites
Tiger

Thanks for your help.


My UDFs:- _RegEnumKey

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  

×