Commands & Syntax > Commands > Xml Parser >

www.perfectkeyboard.com

 

Navigate to Element - < xml_element_navigate >() ... [Pro]

 

XML Navigate to Element
<xml_element_navigate>(Element handle variable,"Path",Element handle variable)
Available in: Professional edition

This command navigates to an Xml file element.

 

#

Parameter name

Parameter description

1

Element handle variable

Starting element handle - variable that identifies the element where the path starts.

2

Path

Path to element to navigate to in form "element2\element3\...\elementX" where "element2" is the first child of the starting elemenet, "elemenet3" is the first child of "element2", etc.

3

Element handle variable

Name of variable that will receive handle of the element from the path ("elementX").

 

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 = "%v2XmlRoot%", Path = "elem1", Element handle variable = "v2ElemNavigated")

23

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

24

IF STRING %vNavigatedValue%!=Hello

25

Message SHOW "Information" : "Navigation to element failed. %vNavigatedValue%" (other parameters: x = -100, y = -100, Window title = Error, Buttons = OK, Timeout (seconds) = 0, Always on top = No).

26

ENDIF

27

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>(%v2XmlRoot%,"elem1",v2ElemNavigated)

<xml_attribute_get>(%v2ElemNavigated%,a1,vNavigatedValue)

<if_str>("%vNavigatedValue%!=Hello")

<msg>(-100,-100,"Navigation to element failed.

%vNavigatedValue%","Error",1,0,0,0)

<endif>

<xml_file_close>(v2XmlDoc)