version 2004.4 (Modified)
DOM SET XML ELEMENT VALUE (elementRef{; xPath; elementValue{; *})
Parameter | Type | Description | |
elementRef | String | XML element reference | |
xPath | Text | XPath path of the XML element | |
elementValue | String | Variable | New value of element | |
* | * | If passed: set the value in CDATA |
Description
The DOM SET XML ELEMENT VALUE command allows you to modify the value of the element set by elementRef.
If you pass the optional xPath parameter, you choose to use XPath notation to indicate the element to be modified (for more information about this notation, refer to the "Use of XPath notation" paragraph in the Presentation of XML Commands section). In this case, you must pass the reference of a root XML element in elementRef and the XPath path of the element to be modified in xPath .
In elementValue, pass a string or a variable (or a field) containing the new value of the specified element:
If you pass a string, the value will be used "as is" in the XML structure.
If you pass a variable or a field, 4th Dimension will process the value, depending on the type of elementValue. All data types can be used, except arrays, pictures and pointers.
When the optional asterisk (*) parameter is passed, this indicates that the value of the element must be set in the form of CDATA. The special CDATA form can be used to write raw text as is (see example 2).
Examples
1. In the following XML source:
<Book> <Title>The Best Seller</Title> </Book>
If the following code is executed, with vElemRef containing the reference to the "Title" element:
DOM SET XML ELEMENT VALUE(vElemRef;"The Loser")
We get:
<Book> <Title>The Loser</Title> </Book>
2. In the following XML source:
<Maths> <Postulate>1+2=3</Postulate> </Maths>
We want to write the text "12<18" in the <Postulate> element. This string cannot be written as is in XML because the "<" character is not accepted. This character must therefore be changed into "<" or the CDATA form must be used. If vElemRef indicates the XML <Postulate> node:
` Normal form DOM SET XML ELEMENT VALUE(vElemRef;"12<18")
We get:
<Maths> <Postulate>12 < 18</Postulate> </Maths>
` CDATA form DOM SET XML ELEMENT VALUE(vElemRef;"12<18";*)
We get:
<Maths> <Postulate><![CDATA[12 < 18]]></Postulate> </Maths>
See Also
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 (for example, if the element reference is invalid).