Presentation is loading. Please wait.

Presentation is loading. Please wait.

Leveraging XML with ColdFusion Jeff Tapper June 2004.

Similar presentations


Presentation on theme: "Leveraging XML with ColdFusion Jeff Tapper June 2004."— Presentation transcript:

1 Leveraging XML with ColdFusion Jeff Tapper June 2004

2 Who am I? Jeff Tapper ColdFusion Developer since 1995 Authored / Edited 6 books on ColdFusion and/or Flash Technologies Macromedia Certified Professional Advanced ColdFusion MX Developer Flash MX Developer Certified Instructor for all CF/Flash Development courses Worked on hundreds of ColdFusion Projects, clients including Toys R Us, Dow Jones, American Express, Allaire, etc. Chief Technologist – Tapper.net Consulting

3 Agenda What is XML How is XML useful ColdFusion and XML XML Document vs. XML Object Parsing XML Creating XML Working with XML in ColdFusion Accessing Elements Searching XML Transforming XML Summary and Questions

4 What is XML eXtensible Markup Language Platform independent description of data W3C Standard Tag Based Easily describes hierarchies within data Useful solution to many problems What XML isnt XML is not HTML Not a presentation language Not a programming language

5 How is XML Useful Data Sharing Inter-company Data Transfer Standardized method to describe data being transferred. Replaces CSV, EDI, etc. Configuration Files Ability to write a single XML file with configuration data usable by CF, Java, Flash, etc. Multilingual Content Store various language versions of same content in single file.

6 XML and ColdFusion XML Documents vs. XML Objects XML Documents Text files Tag based Can be based on Schema or DTD (not covered here) Can be parsed to XML object XML Objects Native CF Datatype Usable as CF Variable, like a structure or array Can be written to text file to create XML Document Can be search and transformed.

7 XML Document OOP with ActionScript 2 Paperback 11/2003 Tapper, Jeff Haffner, Robin Talbot, James Towes, Kevin 540 New Riders

8 XML Terminology OOP with ActionScript 2 Paperback 11/2003 Tapper, Jeff Haffner, Robin Talbot, James Towes, Kevin 540 New Riders Root Node

9 XML Terminology OOP with ActionScript 2 Paperback 11/2003 Tapper, Jeff Haffner, Robin Talbot, James Towes, Kevin 540 New Riders Root Node Tag Attribute Attribute Value

10 XML Terminology OOP with ActionScript 2 Paperback 11/2003 Tapper, Jeff Haffner, Robin Talbot, James Towes, Kevin 540 New Riders Root Node Tag Attribute Attribute Value Child Tags Tag Contents

11 XML and ColdFusion XML Object Native Datatype within ColdFusion Can be parsed from XML Document Read XML File with CFFILE, CFFTP or CFHTTP XMLParse() Can be built from scratch from CF CFXML XMLNew() XMLElemNew()

12 XML and ColdFusion Parsing XML Object from document

13 XML and ColdFusion Creating XML Object with CFXML Object Oriented Programming with ActionScript 2...

14 XML and ColdFusion Creating XML Object with CFXML from a query #title# #LastName#, #firstName#... #DateFormat(publicationDate,"mm/yyyy")# #pages# #style# #publisher#

15 XML and ColdFusion Creating/Modifying XML Object with XML Functions

16 Working with XML Objects Can be parsed as a native data type Can be searched with xmlSearch Uses xPath to query xml Returns an array Can be transformed using xmlTransform Convert to other formats Uses XSL, XSLT

17 Working with XML Objects Using XML Object natively Structure and Array syntax can be used Outputs “Object Oriented Programming with ActionScript 2 #xBooks.books.book[1].title.xmlText#

18 Working with XML Objects Using Array and Structure functions #arrayLen(xBooks.books.book)#5 #arrayLen(xBooks.books.book[1].authors.author) # 3 #arrayLen(xBooks.books.book[4].authors.contrib utionAuthors.author)# 9 #structKeyList(xBooks.books.book)#title, authors, pages, style, publicationDate, publisher #StructCount(xBooks.books.book[1])#6

19 xmlSearch Two attributes Name of XML object to search XPath expression with which to search "SQL" for XML objects Full language with syntax specified by W3C Returns an array of matching elements

20 XMLSearch() Example Returns an array of the 2 books with 'Forta, Ben' as an author

21 XPath Rules Single slashes represent nested elements in a document structure—just like slashes in a URL represent nested folders Double slashes are a wildcard meaning in any parent element – any number of nesting levels XPath comparison statements are enclosed in square brackets Non-numeric attribute or content values to match are enclosed in single quotation marks Attribute names are preceded by symbol XPath searches are case-sensitive

22 XMLSearch() Examples Function CallArra y Len Description xmlSearch(xBooks, 4']") 1All child book elements of the books element that have an ISBN attribute equal to xmlSearch(xBooks, "/books/book/title") 5All title elements that are children of any book element in the books element. xmlSearch(xBooks,"//title")5All title elements located in the xBooks object. xmlSearch(xBooks,"//book[autho rs/author='Forta, Ben']/title") 2All title elements that are children of the book element that has an author named 'Forta, Ben' xmlSearch(xBooks,"//book [publisher='New Riders']") 2All book elements with child element publisher contents equal to ‘ New Riders ’.

23 Transforming XML with xmlTransform() Uses XSLT to apply an XSL Style Sheet to an XML Document Takes two arguments: XML and XSL First argument can be either XML Object or Document Second argument must be text of XSL document

24 xmlTransform() Example #variables.htmlContent#

25 xmlTransform() – XSL File W3C published XSL specification File must be available as a variable in CF (CFHTTP, CFFTP, CFPOP, CFFILE, etc.) Capable of transforming XML document to any text format. Frequently used for showing XML as HTML Useful to transform from one form of XML to another

26 Summary ColdFusion MX includes a wide range of XML Tools XML is (finally!) a native data type in CFMX Same XML files can be read by several different technologies CFMX, Flash, Java,.Net, PHP, etc. XML files are searchable Easily transformed into other types of text files

27 Questions ?

28 Thank you.


Download ppt "Leveraging XML with ColdFusion Jeff Tapper June 2004."

Similar presentations


Ads by Google