Utilizing XML in ColdFusion MX. by Attila Domokos. Speaker Information. Who am I? Attila Domokos Web Programmer at a Twin Cities based web development company 2+ years of ColdFusion, 5 months of CF MX experience PHP and JAVA enthusiast. Agenda. What is XML - the XML syntax
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
by Attila Domokos
Who am I?
More strict than HTML (Proper nesting and closing tags are required.)
Starts with XML declarations
Comments take the same form as they do in HTML (<!- - This is a comment - - >)
DTD (Document Type Definition), XDR (XML Data Reduced Schema) and XSD (XML Schema Definition) are used for describing a document
Validation in IE 5+ browsersXML Syntax
<?xml version=“1.0” encoding=“UTF-8”?>
<!- - This is my first comment - ->
<location name=“San Francisco”>
Preview in Browser
1. Specify the file and its path first <CFSET MyXMLFile = ExpandPath(“company.xml”)>
2. Read the XML file into a string variable <CFFILE ACTION=“READ” FILE=“MyXMLFile” VARIABLE=“MyXMLCode”>
3. Parse the document with XMLParse() function into an XML “object” <CFSET MyXML = XMLParse(MyXMLCode)> VIEW
One root element in XML documents <CFSET xnCompany = MyXml.XmlRoot>
The number of child level elements can be determined with the length of the array
<CFSET nNumLocations = ArrayLen(Locations)>
Each item contained by this array will be another XML element object (has all three properties) VIEW
To display all the locations in the example, you have to loop through the Locations array.
<CFLOOP FROM=1 TO=“#nNumLocations#” INDEX=“I”>
<CFSET xnThisLocation = Locations[i]>
<CFSET sLocationName = xnThisLocation.XmlAttributes[“name”]>
<CFOUTPUT><p>Locations #i# is: <b>#sLocationName#</b></p></CFOUTPUT>
Use nested loops if you want to display the employee’s name under locations from the example (company.xml).
<CFSET arEmployees = xnThisLocation[“employees”].XmlChildren>
<CFSET nNumEmployees = ArrayLen(arEmployees)>
<CFLOOP FROM=1 TO=“#nNumEmployees#” INDEX=“j”>
<CFXML VARIABLE=“MyXml”> XML code </CFXML>
Get the latest articles from Macromedia Designer & Developer Center’s XML feed to your site!
Let’s create this .cfm template together!