Modifying a ColdFusion XML object
681
{
MyDoc.MyRoot.XmlChildren[i] = XmlElemNew(MyDoc,"childNode");
MyDoc.MyRoot.XmlChildren[i].XmlText = "This is Child node " & i &".";
}
</cfscript>
<cfdump var=#MyDoc#>
Creating an XML document object from existing XML
The
XmlParse
function converts an XML document or document fragment represented as a text
string into a ColdFusion document object.
If the XML document is already represented by a string variable, use the
XmlParse
tag directly on
the variable. For example, if your application uses
cfhttp action="get"
to get the XML
document, use the following line to create the XML document object:
<cfset myXMLDocument = XmlParse(cfhttp.fileContent)>
If the XML document is in a file, use
cffile
convert the file to a CFML variable, then use the
XmlParse
tag on the resulting variable. For example, if the XML document is in the file
C:\temp\myxmldoc.xml, use the following code to convert the file to an XML document object:
<cffile action="read" file="C:\temp\myxmldoc.xml" variable="XMLFileText">
<cfset myXMLDocument=XmlParse(XMLFileText)>
Note:
If the file is not encoded with the ASCII or Latin-1 character set, use the
cffile
tag
charset
attribute to specify the file’s character set. For example, if the file is encoded in UTF, specify
charset="UTF-8".
Saving and exporting an XML document object
The
ToString
function converts an XML document object to a text string. You can then use the
string variable in any ColdFusion tag or function.
To save the XML document in a file, use the
ToString
function to convert the document object
to a string variable, then use the
cffile
tag to save the string as a file. For example, use the
following code to save the XML document myXMLDocument in the file
C:\temp\myxmldoc.xml:
<cfset XMLText=ToString(myXMLDocument)>
<cffile action="write" file="C:\temp\myxmldoc.xml" output="#XMLText#">
Modifying a ColdFusion XML object
As with all ColdFusion structured objects, you can often use a number of methods to change the
contents of an XML document object. For example, you often have the choice of using an
assignment statement or a function to update the contents of a structure or an array. The
following section describes the array and structure functions that you can use to modify an XML
document object. The section
“XML document object management reference” on page 683
provides a quick reference to modifying XML document object contents. Later sections describe
these methods for changing document content in detail.
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...