Project

General

Profile

Actions

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.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
-
Target version:
-
Start date:
2005-12-31
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

when parsing this xml code :


<moldb>

&lt;molecule&gt;
&lt;name&gt;Alanine&lt;/name&gt;
&lt;symbol&gt;ala&lt;/symbol&gt;
A
&lt;type&gt;hydrophobic&lt;/type&gt;
&lt;/molecule&gt;
&lt;molecule&gt;
&lt;name&gt;Lysine&lt;/name&gt;
&lt;symbol&gt;lys&lt;/symbol&gt;
K
&lt;type&gt;charged&lt;/type&gt;
&lt;/molecule&gt;

</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)

Actions #1

Updated by Brice BERNARD almost 19 years ago

i made a mistake it's not t3div_lib::array2xml but t3div_lib::xml2array

Actions #2

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

Actions #3

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>

&lt;molecule&gt;
&lt;name&gt;Lysine&lt;/name&gt;
&lt;symbol&gt;lys&lt;/symbol&gt;
K
&lt;type&gt;charged&lt;/type&gt;
&lt;/molecule&gt;

</moldb>

Actions #4

Updated by Dmitry Dulepov almost 19 years ago

Use <molecule index="0">

Actions #5

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...

Actions #6

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.

Actions #7

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...

Actions #8

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.

Actions #9

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>

&lt;molecule index=&quot;1&quot;&gt;
&lt;name&gt;Lysine&lt;/name&gt;
&lt;symbol&gt;lys&lt;/symbol&gt;
K
&lt;type&gt;charged&lt;/type&gt;
&lt;/molecule&gt;

</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).

Actions #10

Updated by Dmitry Dulepov over 16 years ago

Nothing really to do about it. Deassigning from myself

Actions #11

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

Actions #12

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.

Actions

Also available in: Atom PDF