version 11 (Modified)
DOM Find XML element (elementRef; xPath{; arrElementRefs}) elementRef
Parameter | Type | Description | |
elementRef | String | XML element reference | |
xPath | Text | BLOB | XPath path of the element to look for | |
arrElementRefs | String 16 array | List of element references found (if applicable) | |
Function result | elementRef | Reference of the element found (if applicable) |
Description
The DOM Find XML element command allows you to look 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 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.
Examples
1. 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.
2. 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 STRING(16;arrAfound;0) vFound:=DOM Find XML element(vElemRef;"/Root/Elem1/Elem2";arrAfound)
See Also
DOM Count XML elements, DOM Create XML element.
System Variables or Sets
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.
Error Handling
An error is generated when:
The element reference is invalid
The specified xPath path is invalid.