Updates the attributes and value of a node in the XMLDatasource.
<CF_XMLUpdate DATASOURCE="XMLDatasourceObject"
XPATH="XPath"
VALUES="values_structure"
FIELDS="list_of_fields">
Required. The XMLDatasource object that will be updated
Required. An XPath query that specifies the node that will be updated.
Optional. A structure containing a key=value list of attributes to set on the new node. If a key in the structure has the same name as the node name, the value of the node is set to this value. If this value isn't specified, the tag will take it's values from the FORM variable.
Optional. A list of field names from the values structure. This allows only certain keys from the value structure to be used as attributes. If not specified, all the keys of the values structure are used.
The node to be updated is specified using an XPath query. The update values can be specified in several ways, depending upon the values attribute. If it's :
<!--- Create a simple Cached Datasource --->
<CF_XMLDatasource name="People" CachedWithin="#createtimespan(0,0,5,0)#" cachename="People">
<people>
<person age="27" company="Torchbox" id="1">Tom Dyson</person>
<person age="27" company="WildFusion" id="2">David Maddison</person>
<person age="23" company="WildFusion" id="3">Peter Piper</person>
<person age="29" company="Torchbox" id="4">olly</person>
</people>
</CF_XMLDatasource>
<CFPARAM Name="Form.PersonID" Default="1">
<!--- If the form has been submited, update the datasource with the form details --->
<CFIF IsDefined("Form.UpdatePerson")>
<!--- Set the fields to be used from the form ---> <CFSET lFields="age,company">
<!--- Insert the values from the form, into the document ---> <CF_XMLUpdate datasource="People" XPath="//person[@id='#FORM.PersonID#']" fields="#lFields#"> </CFIF>
<!--- Get a list of names from the datasource ---> <CF_XMLQuery Datasource="People" Name="qryPeopleNames"> //person </CF_XMLQuery>
<!--- Get the fields for the selected person ---> <CF_XMLQuery Datasource="People" Name="qryPersonDetails"> //person[@id='#FORM.PersonID#'] </CF_XMLQuery>
<!--- Display a simple update form ---> <FORM Method="POST">
Name :
<!--- Display all the available people in a drop down --->
<select name="personID" onchange="form.submit()">
<CFOUTPUT Query="qryPeopleNames">
<option value="#person_id#" #iif(person_id eq form.personid, "'SELECTED'","''")#>#person#</option>
</CFOUTPUT>
</select><br>
<CFOUTPUT>
Company: <INPUT Type="Text" Name="company" Value="#qryPersonDetails.person_company#"><br>
Age: <INPUT Type="Text" Name="age" Value="#qryPersonDetails.person_age#"><br>
<INPUT type="submit" name="UpdatePerson" value="Update Person">
</CFOUTPUT>
</FORM>
<!--- Display the datasource as it is at the moment ---> <CF_XMLDump Datasource="People">
|
|
|
| Produced by Tom Dyson of Torchbox, and David Maddison of Wildfusion | |