new xml features in cfmx 06.21.03 samuel neff
DESCRIPTION
New XML Features in CFMX 06.21.03 Samuel Neff. Outline. XML XPath XSLT What's next?. New XML Features in CFMX – 06.21.03. What is XML?. Format for combining data and metadata Data is the information being exchanged A person's name An account number - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/1.jpg)
New XML Features in CFMX06.21.03
Samuel Neff
![Page 2: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/2.jpg)
Outline
XML
XPath
XSLT
What's next?
New XML Features in CFMX – 06.21.03
![Page 3: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/3.jpg)
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
What is XML?
New XML Features in CFMX – 06.21.03
![Page 4: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/4.jpg)
Exchange of data between applications
Movement of data within tiers of an application
Storage of highly complex single-purpose data
Where to use XML?
New XML Features in CFMX – 06.21.03
![Page 5: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/5.jpg)
Movement of data within components of a single-tier in an application
Storage of reusable or relational data
Where NOT to use XML?
New XML Features in CFMX – 06.21.03
![Page 6: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/6.jpg)
Anatomy of an XML Document
<?xml version='1.0'?><people> <person firstName="Doug" lastName="Jones"> <bio> Doug is a broker. </bio> <!-- Do we have more info on Doug? --> </person></people>
Processing Instructions
Elements
Attributes
Data
Comments
(Comments have only two dashes in XML)
New XML Features in CFMX – 06.21.03
![Page 7: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/7.jpg)
Parsing an XML File
<cfset fileName = expandPath("Simple.xml")>
<cffile action = "read" file="#fileName#" variable="xmlText">
<cfset xmlObject = xmlParse(xmlText)>
<cfdump var = "#xmlObject#" label = "xmlObject">
Example: 1_ReadXML.cfm
New XML Features in CFMX – 06.21.03
![Page 8: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/8.jpg)
Accessing XML Elements
Use simple dot notation to access elements
<cfset firstNameElement = xmlObject.purchaseOrder.customerInfo.firstName>
Use the XML object property "xmlText" to read the text of an element
<cfset firstNameText = firstNameElement.xmlText> <cfoutput>#firstNameText#</cfoutput>
Example: 2_XMLElements.cfm
New XML Features in CFMX – 06.21.03
![Page 9: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/9.jpg)
Accessing XML Attributes
Use the XML element property "xmlAttributes" to read the attributes
xmlAttributes is a structure of key/value pairs
<cfset customerInfoElement = xmlObject.purchaseOrder.customerInfo>
<cfset customerId = customerInfoElement.xmlAttributes.customerId>
<cfoutput><h1> The customer id is #customerId# </h1></cfoutput>
Example: 3_XMLAtts.cfm
New XML Features in CFMX – 06.21.03
![Page 10: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/10.jpg)
Iterating XML Nodes
Use standard structure functions to iterate attributes <cfset atts = arguments.element.xmlAttributes> <cfloop item="i" collection="#atts#"> <cfset attValue = atts[i]> </cfloop>
Use the XML object property "xmlChildren" as an array of child elements
<cfset children = element.xmlChildren> <cfloop index="i" from="1" to="#arrayLen(children)#"> <cfset child = children[i]> </cfloop>
Example: IterateXML.cfm, 4_IterateXML.cfm
New XML Features in CFMX – 06.21.03
![Page 11: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/11.jpg)
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
What is XPath?
Example: 5_DisplayComplex.cfm
New XML Features in CFMX – 06.21.03
![Page 12: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/12.jpg)
Use XMLSearch() function to perform an XPath search
<cfset nodes = XMLSearch(xmlObject, "/purchaseOrders/purchaseOrder/customerInfo/firstName")>
First argument is an XML object—already parsed
Second argument is an XPath Expression
XPath expression is forward slash delimited list of elements
XMLSearch Returns an array of XML Elements
Simple node selection
Example: 6_SimpleXPath.cfm
New XML Features in CFMX – 06.21.03
![Page 13: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/13.jpg)
Filtered node selection
Use square brackets to indicate a filter
Use relative paths to identify comparison nodes
/purchaseOrders/purchaseOrder/customerInfo [../products/product/discount > 0]
Example: 7_FilteredXPath.cfm, 8_FilteredXPath.cfm
Use @ sign to indicate an attribute
Still include '/' before the @ sign
/purchaseOrders/purchaseOrder/customerInfo [../products/product/@productId = 1]
New XML Features in CFMX – 06.21.03
![Page 14: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/14.jpg)
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/@customerId
Above valid XPath won't work in ColdFusion MX
New XML Features in CFMX – 06.21.03
![Page 15: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/15.jpg)
Language for transforming one XML document into another XML document or into text
An XSLT transformation is also a valid XML document
What is XSLT
New XML Features in CFMX – 06.21.03
![Page 16: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/16.jpg)
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
XML to XML Transformations
Example: 09_XSLT_XML.xsl, 10_XSLT_XML.cfm
New XML Features in CFMX – 06.21.03
![Page 17: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/17.jpg)
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
![Page 18: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/18.jpg)
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
![Page 19: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/19.jpg)
CML
What's next?
DCDDOMDTDJAXPMathM
LMTXP3PRDFRSS
SMILSOAPSVGTLDUDDIVMLWDD
XWMLWSD
LXAG
XDRXFormsXHTMLXKM
SXLinkXPointerXQLXSDXSL-FO…
New XML Features in CFMX – 06.21.03
![Page 20: New XML Features in CFMX 06.21.03 Samuel Neff](https://reader036.vdocument.in/reader036/viewer/2022070416/568151b5550346895dbfe223/html5/thumbnails/20.jpg)
Blog: http://www.rewindlife.com
E-Mail:[email protected]
Questions
New XML Features in CFMX – 06.21.03