New XML Features in CFMX - PowerPoint PPT Presentation

About This Presentation
Title:

New XML Features in CFMX

Description:

Combining data and metadata into one file simplifies development and interoperability ... Supports combining disparate nodes. Supports filtering nodes by ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 21
Provided by: DraM
Learn more at: http://www.cfconf.org
Category:

less

Transcript and Presenter's Notes

Title: New XML Features in CFMX


1
New XML Features in CFMX 06.21.03 Samuel
Neff
2
Outline
  • XML
  • XPath
  • XSLT
  • What's next?

New XML Features in CFMX 06.21.03
3
What is XML?
  • Format for combining data and metadata
  • Data is the information being exchanged
  • A person's name
  • An account number
  • Metadata is the descriptor of that information
  • "Name"
  • "AccountNumber"
  • Combining data and metadata into one file
    simplifies development and interoperability

New XML Features in CFMX 06.21.03
4
Where to use XML?
  • Exchange of data between applications
  • Movement of data within tiers of an application
  • Storage of highly complex single-purpose data

New XML Features in CFMX 06.21.03
5
Where NOT to use XML?
  • Movement of data within components of a
    single-tier in an application
  • Storage of reusable or relational data

New XML Features in CFMX 06.21.03
6
Anatomy of an XML Document
lt?xml version'1.0'?gt ltpeoplegt ltperson
firstName"Doug" lastName"Jones"gt ltbiogt
Doug is a broker. lt/biogt lt!-- Do we
have more info on Doug? --gt
lt/persongt lt/peoplegt
Processing Instructions
Elements
Attributes
Data
Comments
(Comments have only two dashes in XML)
New XML Features in CFMX 06.21.03
7
Parsing an XML File
ltcfset fileName expandPath("Simple.xml")
gt ltcffile action "read" file"fileName"
variable"xmlText"gt ltcfset xmlObject
xmlParse(xmlText)gt ltcfdump var "xmlObject"
label "xmlObject"gt
Example 1_ReadXML.cfm
New XML Features in CFMX 06.21.03
8
Accessing XML Elements
  • Use simple dot notation to access elements
  • ltcfset firstNameElement
  • xmlObject.purchaseOrder.customerInfo.fi
    rstNamegt
  • Use the XML object property "xmlText" to read the
    text of an element
  • ltcfset firstNameText firstNameElement.xmlTex
    tgt
  • ltcfoutputgtfirstNameTextlt/cfoutputgt

Example 2_XMLElements.cfm
New XML Features in CFMX 06.21.03
9
Accessing XML Attributes
  • Use the XML element property "xmlAttributes" to
    read the attributes
  • xmlAttributes is a structure of key/value pairs
  • ltcfset customerInfoElement
  • xmlObject.purchaseOrder.customerInfogt
  • ltcfset customerId
  • customerInfoElement.xmlAttributes.custo
    merIdgt
  • ltcfoutputgtlth1gt
  • The customer id is customerId
  • lt/h1gtlt/cfoutputgt

Example 3_XMLAtts.cfm
New XML Features in CFMX 06.21.03
10
Iterating XML Nodes
  • Use standard structure functions to iterate
    attributes
  • ltcfset atts arguments.element.xmlAttributesgt
  • ltcfloop item"i" collection"atts"gt
  • ltcfset attValue attsigt
  • lt/cfloopgt
  • Use the XML object property "xmlChildren" as an
    array of child elements
  • ltcfset children element.xmlChildrengt
  • ltcfloop index"i" from"1" to"arrayLen(childre
    n)"gt
  • ltcfset child childrenigt
  • lt/cfloopgt

Example IterateXML.cfm, 4_IterateXML.cfm
New XML Features in CFMX 06.21.03
11
What is XPath?
  • Language for selecting nodes from an XML document
  • Supports combining disparate nodes
  • Supports filtering nodes by complex criteria
  • Think of it as single-table SQL

Example 5_DisplayComplex.cfm
New XML Features in CFMX 06.21.03
12
Simple node selection
  • Use XMLSearch() function to perform an XPath
    search
  • ltcfset nodes XMLSearch(xmlObject,
  • "/purchaseOrders/purchaseOrder/customerInfo/firs
    tName")gt
  • First argument is an XML objectalready parsed
  • Second argument is an XPath Expression
  • XPath expression is forward slash delimited list
    of elements
  • XMLSearch Returns an array of XML Elements

Example 6_SimpleXPath.cfm
New XML Features in CFMX 06.21.03
13
Filtered node selection
  • Use square brackets to indicate a filter
  • Use relative paths to identify comparison nodes
  • /purchaseOrders/purchaseOrder/customerInfo
  • ../products/product/discou
    nt gt 0
  • Use _at_ sign to indicate an attribute
  • Still include '/' before the _at_ sign
  • /purchaseOrders/purchaseOrder/customerInfo
  • ../products/product/_at_produc
    tId 1

Example 7_FilteredXPath.cfm, 8_FilteredXPath.cfm

New XML Features in CFMX 06.21.03
14
ColdFusion MX XPath Limitations
  • Can only be used to select XML Elements
  • In other systems you can select attribute nodes
    as well
  • /purchaseOrders/purchaseOrder/customerInfo/_at_cust
    omerId
  • Above valid XPath won't work in ColdFusion MX

New XML Features in CFMX 06.21.03
15
What is XSLT
  • Language for transforming one XML document into
    another XML document or into text
  • An XSLT transformation is also a valid XML
    document

New XML Features in CFMX 06.21.03
16
XML to XML Transformations
  • Refactor an XML document
  • Move, sort and rename nodes
  • Filter out data
  • Commonly used for inter-application data exchange
    when each application already has an existing XML
    grammar

Example 09_XSLT_XML.xsl, 10_XSLT_XML.cfm
New XML Features in CFMX 06.21.03
17
XML to HTML Transformations
  • Reporting from XML
  • Simpler than DOM processing

Example 11_XSLT_HTML.xsl, 12_XSLT_HTML.cfm
New XML Features in CFMX 06.21.03
18
ColdFusion MX XSLT Limitations
  • No parameters to XSLT transformation
  • No caching of compiled XSLT files
  • Extra XML serialization and deserialization
    sometimes necessary

New XML Features in CFMX 06.21.03
19
What's next?
CML
SMIL
XDR
DCD
SOAP
XForms
DOM
SVG
XHTML
DTD
TLD
XKMS
JAXP
UDDI
XLink
MathML
VML
XPointer
MTX
WDDX
XQL
P3P
WML
XSD

RDF
WSDL
XSL-FO
RSS
XAG
New XML Features in CFMX 06.21.03
20
Questions
Blog http//www.rewindlife.com E-Mail sam_at_rewind
life.com
New XML Features in CFMX 06.21.03
Write a Comment
User Comments (0)
About PowerShow.com