Commands & Syntax > Commands > Xml Parser >

Element Get - < xml_element_get >() ... [Pro]

www.perfectkeyboard.com

 

XML Element Get
<xml_element_get>(Element handle variable,What,Variable receiving result)
Available in: Professional edition

This command provides access to an Xml file element information such as name, text, child elements, etc.

 

#

Parameter name

Parameter description

1

Element handle variable

Element handle - variable that identifies the element to get information from.

2

What

Type of information to retrieve:
SIBLING_NEXT - identifier of next sibling element.
SIBLING_PREV - identifier of previous sibling element.
CHILD_FIRST - identifier of first child element.
CHILD_LAST - identifier of last child element.
TEXT - the element text.
NAME - the element name.
PATH - the element path in the XML from root. For example, "contacts\contact\address\street" for the "street" element that is child of the "address" element...

3

Variable receiving result

Name of variable that will receive retrieved information.

 

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)