In addition to the basic reading and writing of XML data, ColdFusion also supports XSL styles, XPath searches, and low-level access to XML data when needed. Applying XSL StylesheetsXSL (Extensible Stylesheet Language) is used to define formatting and output instructions to be applied to XML. ColdFusion itself does not create or manage XSL style sheets, but it does provide a function that may be used to apply style sheetsreturning the transformed data. The process of applying style sheets is known as XSLT (Extensible Stylesheet Language Transformation) and is performed using the XMLTransform() function, like this: <cffile action="read" file="C:\cfusionmx7\wwwroot\xsl\standard.xsl" variable="xslDoc"> <cfoutput> #XMLTransform(users, xslDoc)# </cfoutput> Here an XSL style sheet is read using <cffile> and then used in an XMLTransform(). NOTE XMLTransform() can take an XML Document Object and an XML document (in string form) as its first argument. Performing SearchesExtracting data from an XML document is not difficult, but searching for data can be. As XML documents are made up of both data and tags, it can be tricky to search for specific data or tags or at specific nesting levels. XPath is a searching language not unlike what Regular Expressions are for textan XPath search involves creating a search pattern and then using it to extract data from an XML document. XPath is supported in ColdFusion by the XMLSearch() function, which takes a search pattern and an XML Document Object to be searched. A simple example is seen here: <cfset results=XMLSearch(users, "user/UserID")> <cfoutput> Found #ArrayLen(results)# matches </cfoutput> This example searches for user elements containing a UserID element and returns an array of matches. NOTE XPath is defined by the W3; details are at http://www.w3.org/TR/xpath. Other XML FunctionsIn addition to the XML functions used thus far, ColdFusion provides several other XML functions that may be used as needed:
|