Commands & Syntax > Commands > Xml Parser >

www.perfectkeyboard.com

 

Element Create - < xml_element_create >() ... [Pro]

 

XML Element Create
<xml_element_create>(File handle variable,Name,Text,Element handle variable)
Available in: Professional edition

This command creates a new Xml file element. Once the new element is created it can be added to Xml file using "element set" command.

 

#

Parameter name

Parameter description

1

File handle variable

Xml file handle - an Xml file identifier provided from "open xml" or "create xml" commands.

2

Name

Name of the new element.

3

Text

The new element text.

4

Element handle variable

Name of variable that will receive the newly created element handle.

 

Example (Macro Steps):

 

1

<#> <#>This macro shows how to work with Xml file content

2

<#> <#>Create XML file with some simple content and save it to disk

3

Macro execution: ONLY COMMANDS

4

XML File Create vXmlDoc, Root element handle variable = vXmlRoot,Password =

5

XML Element Create (File handle variable = "vXmlDoc", Name = "elem1", Text = "This is elem1 text", Element handle variable = "vElem1")

6

XML Attribute Set (Element handle variable = "vElem1", Attribute name = "a1", Value = "Hello")

7

XML Element Set "vXmlRoot" (What = CHILD_FIRST, Input = vElem1)

8

XML File Save "vXmlDoc" (File path = "%TEMP%\test.xml")

9

XML File Close "vXmlDoc"

10

<#> <#>Open the XML file previously created and explore the contet

11

XML File Open File path = "%TEMP%\test.xml", File handle variable = "v2XmlDoc", Root element handle variable = "v2XmlRoot", Password = ""

12

IF STRING %v2XmlDoc%==%_vStrEmpty%

13

Message SHOW "Information" : "Xml file open failed." (other parameters: x = -100, y = -100, Window title = Error, Buttons = OK, Timeout (seconds) = 0, Always on top = No).

14

ENDIF

15

XML Element Get "v2XmlRoot" (What = CHILD_FIRST, Variable receiving result = v2ElemChild1)

16

IF STRING %v2ElemChild1%==%_vStrEmpty%

17

Message SHOW "Information" : "Xml element not found." (other parameters: x = -100, y = -100, Window title = Error, Buttons = OK, Timeout (seconds) = 0, Always on top = No).

18

ENDIF

19

XML Element Get "v2ElemChild1" (What = NAME, Variable receiving result = v2ElemName)

20

XML Element Get "v2ElemChild1" (What = TEXT, Variable receiving result = v2ElemText)

21

XML Attribute Get (Element handle variable = "%v2ElemChild1%", Attribute name = "a1", Variable for result = "v2A1AttributeValue")

22

XML Navigate to Element (Element handle variable = "v2XmlDoc", Path = "root\elem1", Element handle variable = "v2ElemNavigated")

23

IF STRING %v2ElemNavigated%==%_vStrEmpty%

24

Message SHOW "Information" : "Xml file open failed." (other parameters: x = -100, y = -100, Window title = Error, Buttons = OK, Timeout (seconds) = 0, Always on top = No).

25

ENDIF

26

XML File Close "v2XmlDoc"

Example (Plain Text):

 

<#>This macro shows how to work with Xml file content

<#>Create XML file with some simple content and save it to disk

<cmds>

<xml_file_create>(vXmlDoc,vXmlRoot)

<xml_element_create>(vXmlDoc,elem1,This is elem1 text,vElem1)

<xml_attribute_set>(vElem1,a1,Hello)

<xml_element_set>(vXmlRoot,CHILD_FIRST,vElem1)

<xml_file_save>(vXmlDoc,"%TEMP%\test.xml")

<xml_file_close>(vXmlDoc)<#>Open the XML file previously created and explore the contet

<xml_file_open>("%TEMP%\test.xml",v2XmlDoc,v2XmlRoot)

<if_str>("%v2XmlDoc%==%_vStrEmpty%")

<msg>(-100,-100,"Xml file open failed.","Error",1,0,0,0)

<endif>

<xml_element_get>(v2XmlRoot,CHILD_FIRST,v2ElemChild1)

<if_str>("%v2ElemChild1%==%_vStrEmpty%")

<msg>(-100,-100,"Xml element not found.","Error",1,0,0,0)

<endif>

<xml_element_get>(v2ElemChild1,NAME,v2ElemName)

<xml_element_get>(v2ElemChild1,TEXT,v2ElemText)

<xml_attribute_get>(%v2ElemChild1%,a1,v2A1AttributeValue)

<xml_element_navigate>(v2XmlDoc,"root\elem1",v2ElemNavigated)

<if_str>("%v2ElemNavigated%==%_vStrEmpty%")

<msg>(-100,-100,"Xml file open failed.","Error",1,0,0,0)

<endif>

<xml_file_close>(v2XmlDoc)