Presentation is loading. Please wait.

Presentation is loading. Please wait.

Utilizing XML in ColdFusion MX by Attila Domokos.

Similar presentations


Presentation on theme: "Utilizing XML in ColdFusion MX by Attila Domokos."— Presentation transcript:

1

2 Utilizing XML in ColdFusion MX by Attila Domokos

3 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

4 Agenda What is XML - the XML syntax Parsing the XML document XML element objects Looping through child elements XML search with XPath Generating new XML documents Real World Example

5 What is XML? eXtensible Markup Language XML looks a bit like HTML XML offers a method of putting structured data into a text file XML is machine-readable, human- intelligible XML is license-free, platform-independent and well supported

6 XML Syntax 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 ( ) DTD (Document Type Definition), XDR (XML Data Reduced Schema) and XSD (XML Schema Definition) are used for describing a document Validation in IE 5+ browsers

7 An Example Tom Cruise Ben Forta Nicole Kidman Preview in Browser

8 Parsing the XML Document 1. Specify the file and its path first 2. Read the XML file into a string variable 3. Parse the document with XMLParse() function into an XML “object” VIEWVIEW

9 XML Element Objects I. One root element in XML documents XmlName - the name of the element XmlAttributes – contains all the attributes of the corresponding element VIEW VIEW

10 XML Element Objects II. XmlChildren – An array that contains all the immediate children of the element The number of child level elements can be determined with the length of the array Each item contained by this array will be another XML element object (has all three properties) VIEW VIEW

11 Looping Through Child Elements To display all the locations in the example, you have to loop through the Locations array. Locations #i# is: #sLocationName# VIEW

12 Nested Loops Use nested loops if you want to display the employee’s name under locations from the example (company.xml). #arEmployees[j].XmlText# VIEW

13 XMLSearch() and XPath Querying an XML file is available with the XMLSearch() function through XPath XPath is a way to apply XSLT stylesheets, now think of it as the XML equivalent to the “WHERE” clause in SQL query XPath uses slashes to represent the nested elements

14 Find Elements with XPath XmlSearch(MyXml, “/company/location/employees/person”) This code will find ALL the elements VIEW XmlSearch(MyXml, “/company/location[@name=‘Newton’]/employees/person”) You’ll get only the employees belonging to the “Newton” location VIEW VIEW XmlSearch(MyXml, “/company/location[@name=‘#URL.LocName#’]/employees/person”) Location name passed through URL VIEW VIEW

15 Generating New XML Docs tag to output XML XML code Output the XML as a string – use the ToString() function Once you have the XML code as string, you can save it to disk with, upload it with or send it with VIEW

16 Real World Example Get the latest articles from Macromedia Designer & Developer Center’s XML feed to your site! The XML file can be found at : http://www.macromedia.com/desdev/resources/ macromedia_resources.xml To read the file, use the tag Let’s create this.cfm template together!

17 Credits Devan Shepherd - Teach Yourself XML in 21 days - (2001) - SAMS David Hunter - Beginning XML (2000) - WROX Utilizing XML and XSLT in ColdFusion MX - Nate Weiss (2002 April) -macromedia.com


Download ppt "Utilizing XML in ColdFusion MX by Attila Domokos."

Similar presentations


Ads by Google