ADVANCED macromedia COLDFUSION MX 7 Application Development [Electronic resources]

Ben Forta, Dain Anderson, Brian Baxter, Jeffrey Bouley, Raymond Camden, Adam Churvis, David Churvis, Ken Fricklas, Paul Hastings, Sam Neff, Robi Sen

نسخه متنی -صفحه : 240/ 94
نمايش فراداده

Parsing XML Documents

An XML document by itself is just a string of text. To harness the power of XML, you must

parse it to create an object that ColdFusion can access much like a collection of structures and arrays.

Using XmlParse()

To parse an XML document stored somewhere on disk, use <cffile> and XmlParse(), as demonstrated in Listing 14.2.

Listing 14.2. ParseXML.cfmParsing an XML Document on Disk
<cffile action="READ"
file="#ExpandPath('CompaniesAndEmployees.xml')#"
variable="xmlDocument">
<cfset xmlObject = XmlParse(xmlDocument, "Yes")>
<cfdump var="#xmlObject#">

Figure 14.1 shows the output of xmlObject in the browser.

Figure 14.1. A ColdFusion XML object as displayed by <cfdump>.

That was pretty painless, wasn't it? By parsing the document contents with the XmlParse() function, we converted the XML document into an object that ColdFusion recognizes as a set of employees, rather than just as a string of text.

The "Yes" is the value of the caseSensitive argument to XmlParse(), which makes the created object case-sensitive.