Feature #15342
closedt3div_lib::array2xml problem when encounters multiples of the same tag
0%
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)
Updated by Brice BERNARD almost 19 years ago
i made a mistake it's not t3div_lib::array2xml but t3div_lib::xml2array
Updated by Sebastian Kurfuerst almost 19 years ago
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
Updated by Martin Kutschker almost 19 years ago
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>
Updated by Brice BERNARD almost 19 years ago
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...
Updated by Martin Kutschker almost 19 years ago
Then why do you use t3div_lib::array2xml at all? Use one of PHP's native functions.
Updated by Dmitry Dulepov almost 19 years ago
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...
Updated by Martin Kutschker about 18 years ago
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.
Updated by Dmitry Dulepov about 18 years ago
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).
Updated by Dmitry Dulepov over 16 years ago
Nothing really to do about it. Deassigning from myself
Updated by Steffen Kamper over 16 years ago
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
Updated by Andreas Wolf about 13 years ago
- 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.