Structures_Datagrid_Renderer_XML: Use column names as field names?

From: Date: Mon, 26 Jun 2006 14:48:03 +0000
Subject: Structures_Datagrid_Renderer_XML: Use column names as field names?
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24462@lists.php.net to get a copy of this message
Hi After the last announcements I tried Structures_Datagrid, which is a really useful tool! Anyway I found no way to make the XML renderer use the column name for the field attribute, instead of the field name. I see that it is normally useful to have the field name, but in my case where I have fields with an ID, whose column names are language specific, this leads to an inconsistent behaviour, as this test case shows: <code> $fields = array(2 => 'Last name', 1 => 'First name', 'lang' => 'Language'); $data = array(
    array(2 => 'Smith', 1 => 'John', 'lang' => 'English'),
    array(2 => 'Schmid', 1 => 'Hans', 'lang' => 'German'),
    array(2 => 'Dupont', 1 => 'Jean', 'lang' => 'French')
); // Get datagrid object, bind data require_once 'Structures/DataGrid.php'; $datagrid =& new Structures_DataGrid(); $datagrid->bind($data); // Set columns foreach ($fields as $field_id => $field_name) {
    $datagrid->addColumn(new Structures_DataGrid_Column($field_name, $field_id));
} // Output XML $datagrid->setRenderer(DATAGRID_RENDER_XML); $renderer =& $datagrid->getRenderer(); $renderer->setOptions(array('outerTag' => 'UserList', 'rowTag' => 'User')); $datagrid->render(); exit; </code> This outputs this code, which is considered as not wellformed by Firefox: <?xml version="1.0"?> <UserList> <User>
    <2>Smith</2>
    <1>John</1>
    <lang>English</lang>
</User> <User>
    <2>Schmid</2>
    <1>Hans</1>
    <lang>German</lang>
</User> <User>
    <2>Dupont</2>
    <1>Jean</1>
    <lang>French</lang>
</User> </UserList> While using other renderers such as XLS or CSV create outputs with column names: | Last name | First name | Language |
| Smith     | John       | English  |
| Schmid    | Hans       | Deutsch  |
| Dupont    | Jean       | French   |
I think for consistency reasons it should be possible to make the column name appear in the XML structure (the output should IMO be forced to be wellformed anyway, making the package a useful tool for people not familiar with the specifications of the formats outputted). I don't know very much about XML - I guess some output like the following would be good? <User>
    <field0 id='2' name='Last name'>Smith</field0>
    <field1 id='1' name='First name'>John</field1>
    <field2 id='lang' name='Language'>English</field2>
</User> I appreciate any comments! -- Markus

« previous php.pear.general (#24462) next »