[TYPO3-dev] Processing complex XML data
Marcus Krause
marcus#exp2008 at t3sec.info
Wed Mar 25 09:39:13 CET 2009
Steffen Kamper schrieb:
> Hi Steffen,
>
> Steffen Müller schrieb:
>> Hi.
>>
>> I'm struggling with handling XML data which I import from Amazon AWS. I
>> hope to get some ideas from you.
>>
>> I'm coding an extension which requests XML data from AWS using REST.
>> My idea was to transform the XML to an array for further processing, but
>> it turned out that this is not trivial at all.
>> There's two properties of the XML data which turned out to be a problem:
>>
>> 1) some elements are used several times:
>> <author>Person1</author>
>> <author>Person2</author>
>>
>> 2) elements sometimes have attributes:
>> <creator role="editor">Person3</creator>
>> <creator role="translator">Person4</creator>
>>
>> I tried t3lib_div::xml2array() but it does not support 1). I did not
>> find other satisfying solutions in the web which both could handle 1)
>> and 2)
>> Then I tried simplexml_load_string() and used an object instead of an
>> array. But the code got rather complex and looked ugly, because I had to
>> use type casting and juggle with several objects. Also TYPO3 API mostly
>> expect array parameters not objects.
>>
>> Maybe someone has a good recommendation on how to handle complex XML as
>> data basis.
>>
>> Does the CR of FLOW3 have a XML model API?
>>
>
> these structures in XML can't be processed with xml2array, this function
> expect TYPO3-typical XML.
>
> Best you can do is to use php native XML-function for parsing, i had
> good results using SimpleXML
> http://php.net/simplexml
Or, you know, use DOM an XPATH! ;-)
Marcus.
More information about the TYPO3-dev
mailing list