4D v13.4

DOM Find XML element

Home

 
4D v13.4
DOM Find XML element

DOM Find XML element 


 

DOM Find XML element ( elementRef ; xPath {; arrElementRefs} ) -> Function result 
Parameter Type   Description
elementRef  String in XML element reference
xPath  Text in XPath path of the element to look for
arrElementRefs  String array in List of element references found (if applicable)
Function result  String in Reference of the element found (if applicable)

The DOM Find XML element command looks for specific XML elements in an XML structure. The search starts at the element designated by the elementRef parameter.

The XML node to seek is set expressed in XPath notation using the xPath parameter (see the “Use of XPath notation” parameter in the Overview of XML DOM Commands section). Indexed elements can be used.

Note: In conformity with the XML standard, searches will be case sensitive.

The command returns the XML reference of the element found.

When the arrElementRefs string array is passed, the command fills it with the list of XML references found. In this case, the command returns the first element of the arrElementRefs array as the result. This parameter is useful when several elements with the same name exist at the location specified by the xPath parameter.

This example lets you quickly look for an XML element and display its value:

 vFound:=DOM Find XML element(vElemRef;"Items/Book[15]/Title")
 DOM GET XML ELEMENT VALUE(vFound;value)
 ALERT("The value of the element is: \""+value+"\"")

The same search can also be done as follows:

 vFound:=DOM Find XML element(vElemRef;"Items/Book[15]")
 vFound:=DOM Find XML element(vFound;"Book/Title")
 DOM GET XML ELEMENT VALUE(vFound;value)
 ALERT("The value of the element is: \""+value+"\"")

Note: As you can see in the above example, the XPath path must always begin with the name of the current element. This detail is important when you are handling relative XPath paths.

Given the following XML structure:

<Root>
   <Elem1>
      <Elem2>aaa</Elem2>
      <Elem2>bbb</Elem2>
      <Elem2>ccc</Elem2>
   </Elem1>
</Root>

The following code can be used to retrieve the reference of each Elem2 element in the arrAfound array:

 ARRAY TEXT(arrAfound;0)
 vFound:=DOM Find XML element(vElemRef;"/Root/Elem1/Elem2";arrAfound)

If the command has been executed correctly, the system variable OK is set to 1. Otherwise, it is set to 0 and an error is generated.

An error is generated when:

  • The element reference is invalid
  • The specified xPath path is invalid.

 
PROPERTIES 

Product: 4D
Theme: XML DOM
Number: 864

The OK variable is changed by the commandThis command modifies the Error system variable

 
INDEX

Alphabetical list of commands

 
HISTORY 

Modified: 4D v11 SQL

 
SEE ALSO 

DOM Count XML elements
DOM Create XML element