[Typo3-dev] suggestion for t3lib_div::xml2array()
Kasper Skårhøj
kasper at typo3.com
Sat Mar 27 17:01:01 CET 2004
RC2 does something different than RC1; by default numeric arrays are
done by the tag "numIndex" and not "n1", "n2" etc. THis should be good
enough.
- kasper
On Fri, 2004-03-26 at 19:35, Martin T. Kutschker wrote:
> 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.
>
> _______________________________________________
> Typo3-dev mailing list
> Typo3-dev at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev
--
Best regards
- kasper
---------------
"Zero MS-gravity" - finally migrated to Linux!
More information about the TYPO3-dev
mailing list