[Typo3-dev] suggestion for t3lib_div::xml2array()
Martin T. Kutschker
Martin.T.Kutschker at blackbox.net
Fri Mar 26 19:35:42 CET 2004
Hi!
To simplify numeric arrays eg used TCEform types "select" I suggest an
attribute "type" with the currently value of "list" (or "array").
Example (of a nested array):
<TCEforms>
<label>blah</label>
<config>
<type>select</type>
<items type="list">
<item type="list">
<label>foobar</label>
<pos>0</pos>
</item>
</items>
</config>
<TCEforms>
Implementation (only relevant code given):
// Init vars
$listStack = array(array());
// Traverse the parsed XML structure
if ($stackList[$stacktop-1]['list'] &&
($val['type']=='open' || $val['type']=='complete')) {
$tagName = $stackList[$stacktop-1]['cnt']++;
}
// Setting tag-values, manage stack:
case 'open':
$stackList[$stacktop]['list'] =
$val['attributes']['type']=='list' ? true : false;
$stackList[$stacktop]['cnt'] = 0;
----
I also plead for changing a current feature. As it is now the "index"
attribute is used for denoting an alternative node name. OTOH a IMHO
rather unfortunate way for numeric PHP arrays is in place: a "magic"
element name "n" followed by an integer (eg "n2").
I suggest to use the attribute "key" (or "name") for alternative names
and "index" (or even the shorter "idx") for numeric indices.
Example code for the function:
if ($val['attributes']['key']) {
$tagName = $val['attributes']['name'];
}
if ($val['attributes']['idx']) {
$tagName = intval($val['attributes']['idx']);
}
So the XML can be validated against a DTD or a schema.
<T3DataStructure>
<sheets>
<sheet key="sDEF">
...
</sheet>
<sheets>
</T3DataStructure>
----
Minor point:
// $index = array(); // not used
// unused $index opt. removed
xml_parse_into_struct($parser, $string, $vals);
Masi (nitpicking again)
PS: Why is there a ROOT element within the sheet element of the FlexForm
data structure? It looks superfluos to me.
PPS: Is there any chance to change the current "el" to "elements"? So it
looks like this for FlexForms:
<ROOT>
<TCEforms>
<elements>
<el key="field">
</el>
</elements>
</TCEforms>
</ROOT>
It's a few bytes more for the container, but "el" implies a singular.
IMHO it's more easily understood.
More information about the TYPO3-dev
mailing list