[TYPO3-dev] How to use xml2array()

bernd wilke t3ng at bernd-wilke.net
Mon Dec 1 14:03:53 CET 2014


Am 01.12.14 11:29, schrieb Jigal van Hemert:
> Hi,
>
> On 01/12/2014 09:41, bernd wilke wrote:
>> I'm trying to use \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array() to
>> analyse a fluid-template.
>>
>> first problem were the namespace declarations in the beginning of the
>> template. But removing them with preg_replace() solved this.
>>
>>
>> Now I get the Error
>> | Line 2: Invalid document end
>>
>> can't xml2array() handle tags over multiple lines?
>
> xml2array() was designed for parsing flexform values. I have indeed seen

how can you use the function for flexforms?
As I got it running meanwhile I see no values in the reuslt.
there only is the tag-structure , and so there are some tags on the same 
level, only the last tag (or better: structure in tag) is shown in the 
result.

> problems with tags spread over multiple lines if they only contain a value:
> <tag>
>    value
> </tag>
>
> went wrong and
>
> <tag>value</tag>
>
> was no problem.

my problem was another: xml2array() expects to have the whole document 
in one tag.
with the leading
<f:layout name="Content" />
the scan stops as it decided the end of document, but noticed further data.
solution: xml2array('<wrap>' . $content . '</wrap>');

>
>> BTW: I can't figure about the second paramter of xml2array():
>> what is it for?
>> how can I use it?
>
> That parameter can be used to pass a namespace to the function. The xml
> parser that is used apparently returns the tag names including the
> namespace prefix. If a tag is found that starts with the namespace it's
> removed before making an entry in the array.
>
> Perhaps a different XML parser is more useful in this case...

  as said above: no parallel tags, no values, no attributes => no 
possible usage
I think I will use xml2tree(), but that might be to much data. as it 
uses a lot of additional entries in the array I can't assign to anything
(a lot of empty entries in subnodes['values'])


bernd
-- 
http://www.pi-phi.de/cheatsheet.html



More information about the TYPO3-dev mailing list