![]() | ![]() ![]() ![]() |
![]() | |
![]() | |
![]() |
The XMLConnector component provides your application with access to any external data source that returns or receives XML through HTTP. The easiest way to connect with an external XML data source and use the parameters and results of that data source for your application is to specify a schema, the structure of the XML document that identifies the data elements in the document to which you can bind. You can manually create the schema through the Component Inspector panel, or you can use the authoring environment to create one automatically.
For more information on the XMLConnector component, including its properties, methods, and events, see XMLConnector component.
Note: The authoring environment accepts a copy of the external XML document you are connecting to as a model for the schema. If you are familiar with XML scripting, you can create a sample XML file that can be used to generate a schema.
The following are the parameters for the XMLConnector component:
direction A string that defines what type of operation to perform via HTTP when trigger()
is called: send
, sendAndLoad
, or load
correspond to receive
, receive/send
, and send
, respectively.
ignoreWhite A Boolean value; the default setting is false
. When this parameter is set to true
, the text nodes that contain only white space are discarded during the parsing process. Text nodes with leading or trailing white space are unaffected.
multipleSimultaneousAllowed A Boolean value; when this parameter is set to true
, it allows a trigger()
operation to initiate when another trigger()
operation is already in progress. Multiple simultaneous trigger()
operations may not be completed in the same order they were called. Also, Flash Player may place limits on the number of simultaneous network operations. This limit varies by version and platform. When the parameter is set to false
, a trigger()
operation cannot initiate if another one is in progress.
suppressInvalidCall
A Boolean value; when this parameter is set to true
, it suppresses the trigger()
operation if the data parameters are invalid. When it is set to false
, the trigger()
operation executes and uses invalid data if necessary.
URL A string that points to an external XML data source.
The typical workflow for the XMLConnector component is as follows.
Note: You can use the Import Sample Schema button to automate this process.
params
and results
) from the XML document to properties of the visual components in your application. For example, you can connect to an XML document that provides weather data and bind the Location and Temperature data elements to label components in your application. The name and temperature of a specified city appears in the application at runtime.The key to using XML documents and data binding is to import a schema (the data structure that appears in the Schema panel) that you can then bind to.
The schema appears in the Schema tab
For example, the schema for a file named Animals.xml looks like the following:
This is a schematic representation of the structure of the XML file. It says that the results
property of the XMLConnector component is an XML object. The root element of that object is called Inventory, which contains the elements Vendor, categories, and so on. The Vendor element contains a single element called Name, which is a string. The categories field contains an element called Birds, which contains the attribute labelname
. The Birds element also contains an array of objects called Bird. Each of these objects has two attributes: name
and url
. It also contains a single element named key, which contains the attribute id
.
The String and Integer fields can be bound to a variety of UI components. The Array field Bird can be bound to List, DataGrid, or ComboBox components, or you can directly bind UI components to fields within the array. A typical workflow for an application that works with data would include binding an array from the XMLConnector component to the DataSet component's dataProvider
property. In this scenario, the data set could be used to manage the data. The fields within the data set could then be mapped to any of the UI components using data binding.
If the structure of the XML data provided to your application is not of the desired form, a virtual schema allows you to change how the underlying data structure is interpreted when bindings are executed. The new structure is derived using XPath statements. See Supported XPath expressions.
For example, the schema for animals.xml file described previously (see Importing schemas for XML data sources) defines an array of objects called Bird. Each object contains two fields (name
and url
). They also contain a subelement with one field called id
. If you bind the Bird array to a DataSet component (using the dataProvider
property) with three fieldsname
, url
, and id
each item that is returned from the array is constructed with this algorithm:
For each item in the XML:
The ID field does not exist on the item, and the DataSet component has a blank entry for each item assigned.
The solution is to create a new schema field under the object within the Bird array. The new schema field is named id
. Every schema field has a property called path
that accepts an XPath statement that points to the data in your XML file. In this case the XPath statement would be key/@id. When you get to step 2 in this procedure, data binding finds an id
field for the object. It looks at the path
property and uses the XPath statement to get the correct data from the XML file. The correct data is then passed to the DataSet component. For information on manually creating a schema, see Working with schemas in the Schema tab (Flash Professional only).
The following XPath expressions are supported:
/A/B/C
A/B/C
/A/B/C
(node selection by name)
/A/B/*
(node selection of all child nodes of /A/B by wildcard)
/*/*/C
(node selection of all C nodes that have exactly two ancestors)
/B[C]
(child node syntax; selects all B nodes that have a C node as a child)
/B[@id]
(attribute existence syntax; selects all B nodes that have an attribute named id
)
/B[@id="A1"]
(attribute value syntax; selects all B nodes that have an id
attribute whose value is A1)
=
AND
and OR
values in predicates:
/B[@id=1
AND @customer="macromedia"]
Note: The following operators are not supported: "<", ">", "//".
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |