Jump to content
Sign in to follow this  

Create XML file

Recommended Posts


I would like to create a xml file.

This is the xml file.

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

My UDFs:- _RegEnumKey

Share this post

Link to post
Share on other sites

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.")

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& _


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


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

#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)

;Open created file

_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

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.