Feature #15342
closed
t3div_lib::array2xml problem when encounters multiples of the same tag
Added by Brice BERNARD almost 19 years ago.
Updated about 13 years ago.
Description
when parsing this xml code :
<moldb>
<molecule>
<name>Alanine</name>
<symbol>ala</symbol>
A
<type>hydrophobic</type>
</molecule>
<molecule>
<name>Lysine</name>
<symbol>lys</symbol>
K
<type>charged</type>
</molecule>
</moldb>
we have this array :
Array
(
[molecule] => Array
(
[name] => Lysine
[symbol] => lys
[code] => K
[type] => charged
)
)
The tags are overwriting it would be great to obtain this instead (when multiple tags...) :
Array
(
[molecule] => Array
[0] =>
(
[name] => Alanine
[symbol] => ala
[code] => A
[type] => hydrophobic
)
[1] =>
(
[name] => Lysine
[symbol] => lys
[code] => K
[type] => charged
)
)
(issue imported from #M2149)
i made a mistake it's not t3div_lib::array2xml but t3div_lib::xml2array
Hi,
I am not sure if this XML is correct - I think so but it is used a bit sub-optimal as it would make more sense to do it like this:
<molecule name="alanine" symbol="ala" code="a" />
but anyway the TYPO3 XML parser is not capable of this or the example you gave. Please post in -dev for this to find a solution, I think that is important for more people.
Greets, Sebastian
I think this is what you want:
<moldb type="array">
<molecule >
<name>Alanine</name>
<symbol>ala</symbol>
A
<type>hydrophobic</type>
</molecule>
<molecule>
<name>Lysine</name>
<symbol>lys</symbol>
K
<type>charged</type>
</molecule>
</moldb>
I know <molecule index="0"> works but I cannot use it because I can't modify the xml... I just retrieve this xml code.
I'll try to make a patch soon...
Then why do you use t3div_lib::array2xml at all? Use one of PHP's native functions.
Patch is not a bad idea, a number of people on the lists already asked this question. Since it pops up from time to time, it is better to resolve on the typo3 level...
Maybe we could try and use callbacks instead of reparsing the array returned by xml_parse_into_struct(). This could be faster for large xml data.
Solving this problem can make xmk2array incompatible with existing code. If there is "index" attribute, xml2array does not create subindexes like inthe bug report. For example:
<?xml version="1.0"?>
<moldb>
<molecule index="0">
<name>Alanine</name>
<symbol>ala</symbol>
A
<type>hydrophobic</type>
</molecule>
<molecule index="1">
<name>Lysine</name>
<symbol>lys</symbol>
K
<type>charged</type>
</molecule>
</moldb>
we have this
will create:
Array
(
'moldb' => array(
[0] =>
(
[name] => Alanine
[symbol] => ala
[code] => A
[type] => hydrophobic
)
[1] =>
(
[name] => Lysine
[symbol] => lys
[code] => K
[type] => charged
)
)
)
So there is no <molecule> at all. TYPO3 code relies on this (for example, section processing).
Nothing really to do about it. Deassigning from myself
as we have php5.2 as a requirement it's more easy to use simplexml for such files/strings
http://php.net/simplexml
t3lib_div::xml2array are more useful for locallang-like xml files
- Status changed from New to Closed
- Target version deleted (
0)
- TYPO3 Version changed from 3.8.1 to 4.0
- PHP Version deleted (
4)
Closing this as nothing has happened for three years.
Also available in: Atom
PDF