310 likes | 329 Views
XML – Its Role and Use. Ben Forta Senior Product Evangelist, Macromedia. Agenda. The Problem Introducing XML Working with XML ColdFusion MX and XML Web Services. The Problem. An Example. Organization A works with a supplier (organization B)
E N D
XML – Its Role and Use Ben Forta Senior Product Evangelist, Macromedia
Agenda • The Problem • Introducing XML • Working with XML • ColdFusion MX and XML • Web Services
An Example • Organization A works with a supplier (organization B) • Organization A does not have access to organization B's IT systems
The Problem • All interaction between the two organizations is manual • Order submission • Status checking • Payment • Reporting
The Need • The two organizations need to share information, despite differing environments and incompatible applications
What XML Is Not • XML is not a way to format page layout (as is HTML) • XML is not a presentation language
What Is XML • XML is less a “language” per se, and more a way to describe data • XML data is described using “vocabularies”
Understanding XML • XML serves two primary purposes: • Provides a framework to separate data from presentation and layout • Provides a syntax that allows applications to share data • XML defines common information formats across nearly every major computing endeavor
Example - The Challenge • An organization relies on multiple suppliers, each of whom uses a different computer system and thus a different way to describe parts • The challenge is to retrieve real time status information from multiple sources so as to be able to present it in a consistent format
Example - The Solution • An XML format (a “vocabulary”) is agreed upon ahead of time, by the suppliers • Each supplier publishes data in the agreed upon format • The client retrieves the standardized data as needed
Example - Sample Data • Sample XML vocabulary<ORDER_STATUS> <SUPPLIER_ID>123</SUPPLIER> <ORDER_NUM>A24680</ORDER_NUM> <STATUS>Shipped</STATUS> <SHIP_DATE>20020101</SHIP_DATE> <SHIP_VIA>UPS</SHIP_DATE> ...</ORDER_STATUS>
XML Terminology • DTD – data definition document describing the XML data (sometimes called a schema) • DOM – document object model, a hierarchical view of XML content • Node – an item in the DOM, nodes are made up of a type, a name, and a value • Root – top level element in a document • Element – the actual content
Displaying XML Data • XML is NOT a page layout language • XML describes data • XML data can be displayed in any client technology, including HTML, Flash, Java, JavaScript, ActiveX
Working with XML • Working with XML requires tools that can manipulate structured XML data • Read values • Walk trees • Search for and extract specific elements • Set values and build trees
Applying Transformations • XSL is a template language that is used to provide display rules for XML data • XML is data, XSL is a set if display rules • XSL is applied to XML generating a transformation (the actual output)
ColdFusion MX and XML • ColdFusion provides build in support for: • Reading XML data • Writing XML content • Applying XSL transformation • Performing XPath searches
XML In ColdFusion • Within ColdFusion, XML documents are accessed as objects • An XML object in ColdFusion is a structure, and can be access as such • Objects are created using: • <CFXML> • XMLNew() • XMLParse()
Reading XML Data • XMLParse() converts an xml document into an XML object • <CFFILE ACTION="read" FILE="#xmlfile#" VARIABLE="xmldata"> <CFSET xmlobj=XMLParse(xmldata)><CFOUTPUT> #root.order_status.status#</CFOUTPUT>
Writing XML Content • <CFXML> or XMLNew() creates XML objects that may be populated as needed<!--- Create XML object ---><CFXML VARIABLE="Orders"> <Orders> <!--- Loop through orders ---> <CFOUTPUT QUERY="orders"> <!--- Write order ---> <order> <ordnum>#ordnum#</ordnum> <status>#status#</status> </order> </CFOUTPUT> </Orders></CFXML>
Applying XSL Transformations • XSL transformation are applied using XMLTransform() • <CFOUTPUT>#XMLTransform(xmlfeed, xsldoc)#</CFOUTPUT>
Performing XPath Searches • XPath is a search language used to find and extract values from an XML document • XPath uses search patterns to specify search criteria • <CFSET result=XMLSearch(xmlfeed, pattern)>
Why Web Services? • XML is data and facilitates data sharing • Web Services are distributed applications built on top of XML (and SOAP) • Where XML formats data for sharing, SOAP facilitates that sharing
Access to Web Services • <CFINVOKE> provides access to any Web Services<CFINVOKE WEBSERVICE="http://www.xmethods.net/sd/2001/BabelFishService.wsdl"METHOD="BabelFish"TRANSLATIONMODE="en_fr"SOURCEDATA="Hello, my name is Ben"RETURNVARIABLE="name_french"><CFOUTPUT>#name_french#</CFOUTPUT>
Publishing Web Services • Any ColdFusion components can be made accessible as a Web service by simply defining the ACCESS in the component methodACCESS="remote" • ColdFusion Components and methods may be secured using: • User roles • Access levels
Summary • XML is data sharing • ColdFusion MX makes XML usable • Web Services facilitate distributed XML data sharing