Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1074

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
The following example converts an XML text document in a file to an XML document object:
<cfset myXMLDocument=XmlParse("C:\temp\myxmldoc.xml" variable="XMLFileText")>
The
function takes a second, optional, attribute that specifies whether to maintain the case of the elements
XmlParse
and attributes in the document object. The default is to have the document object be case-insensitive. For more
information on case sensitivity, see
The
function also lets you specify a DTD or Schema to validate the XML text; if the XML is not valid,
XmlParse
ColdFusion generates an error. You can specify the filename or URL of the validator, or the DTD or Schema can be in
a CFML variable. You can also tell ColdFusion to use a DTD or Schema that is identified in the XML text. If you specify
validation, also specify whether the document is case sensitive. The following example validates an XML document
on file using a DTD that it specifies using a URL:
myDoc=XMLParse("C:\CFusion\wwwroot\examples\custorder.xml", false,
"http://localhost:8500/examples/custorder.dtd")>
Saving and exporting an XML document object
The
function converts an XML document object to a text string. You can then use the string variable in any
ToString
ColdFusion tag or function.
To save the XML document in a file, use the
then use the
tag to save the string as a file. For example, use the following code to save the XML document
cffile
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 several 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. You can use array and structure functions that you can use to modify an XML
document object. The section
reference to modifying XML document object contents. Later sections describe these methods for changing document
content in detail.
Functions for XML object management
The following table lists the ColdFusion array and structure functions that you can use to manage XML document
objects and their functions, and describes their common uses. In several cases you can use either an array function or
a structure function for a purpose, such as for deleting all of an element's attributes or children.
Function
Use
ArrayLen
Determines the number of child elements in an element, that is, the number of elements in an element's
XmlChildren
ArrayIsEmpty
Determines whether an element has any elements in its
StructCount
Determines the number of attributes in an element's
StructIsEmpty
Determines whether an element has any attributes in its
Returns
"Referencing the contents of an XML
function to convert the document object to a string variable,
ToString
"XML document object management
array.
if the specified structure, including the XML document object or an element, exists and is empty.
True
Last updated 1/20/2012
object" on page 1064.
reference" on page 1071 provides a quick
XmlChildren
array.
XmlAttributes
structure.
structure.
XmlAttributes
1069

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents