This class is a DataSource driver for XML data. It accepts strings and filenames. An XPath expression can be specified to extract a subset from the given XML data.
This driver supports the following operation modes:
Mode | Supported? |
---|---|
Multiple field sorting | no |
Insert, update and delete records | no |
This driver accepts the following options:
Option | Type | Description | Default Value |
---|---|---|---|
fieldAttribute | string | Which attribute of the XML source should be used as column field name (only used if the XML source has attributes). | null |
fields | array | Which data fields to fetch from the datasource. An empty array means: all fields. Form: array(field1, field2, ...) | array() |
generate_columns | bool | Generate Structures_DataGrid_Column objects with labels. See the 'labels' option. DEPRECATED: use Structures_DataGrid::generateColumns() instead | false |
labelAttribute | string | Which attribute of the XML source should be used as column label (only used if 'generate_columns' is true and the XML source has attributes). | null |
labels | array | Data field to column label mapping. Only used when 'generate_columns' is true. Form: array(field => label, ...) DEPRECATED: use Structures_DataGrid::generateColumns() instead | array() |
natsort | boolean | Whether the array should be sorted naturally (e.g. example1, Example2, test1, Test2) or not (e.g. Example2, Test2, example1, test1; i.e. capital letters will come first). | false |
primaryKey | array | Name(s), or numerical index(es) of the field(s) which contain a unique record identifier (only use several fields in case of a multiple-fields primary key) | null |
xpath | string | XPath to a subset of the XML data. | '' |
Bind a simple XML string
<?php
$xml = <<<XML
<records>
<record>
<firstname>Olivier</firstname>
<lastname>Guilyardi</lastname>
<city>Paris</city>
<country>France</country>
</record>
<record>
<firstname>Mark</firstname>
<lastname>Wiesemann</lastname>
<city>Aachen</city>
<country>Germany</country>
</record>
</records>
XML;
// Options for the bind() call (empty in this example)
$options = array();
// Bind the XML string
$test = $datagrid->bind($xml, $options, 'XML');
// Print binding error if any
if (PEAR::isError($test)) {
echo $test->getMessage();
}
?>
Bind a more complex XML string (using 'xpath' option)
<?php
$xml = <<<XML
<response>
<date>today</date>
<server>localhost</server>
<records>
<record>
<firstname>Olivier</firstname>
<lastname>Guilyardi</lastname>
<city>Paris</city>
<country>France</country>
</record>
<record>
<firstname>Mark</firstname>
<lastname>Wiesemann</lastname>
<city>Aachen</city>
<country>Germany</country>
</record>
</records>
</response>
XML;
// Options for the bind() call
$options = array('xpath' => '/response/records');
// Bind the XML string
$test = $datagrid->bind($xml, $options, 'XML');
// Print binding error if any
if (PEAR::isError($test)) {
echo $test->getMessage();
}
?>