4D v14.3DOM Find XML element |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
DOM Find XML element
|
DOM Find XML element ( elementRef ; xPath {; arrElementRefs} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
elementRef | String |
![]() |
XML element reference | |||||
xPath | Text |
![]() |
XPath path of the element to look for | |||||
arrElementRefs | String array |
![]() |
List of element references found (if applicable) | |||||
Function result | String |
![]() |
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:
Product: 4D
Theme: XML DOM
Number:
864
Modified: 4D v11 SQL
DOM Count XML elements
DOM Create XML element
4D Language Reference ( 4D v11 SQL Release 6)
4D Language Reference ( 4D v12.4)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)