FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=18395&edit=1

ID: 18395
Comment by: nadeem.shafi@simplestream.com
Reported By: nadeem dot shafi at simplestream dot com
Summary: problem adding items with same name
Status: Open
Type: Documentation Problem
Package: XML_Serializer
Operating System: centos
Package Version: SVN
PHP Version: 5.3.0
Roadmap Versions:
New Comment:

i fixed it !!

You have to tell the constructor with option use simpleXml

$serializer(array(
'mode' => 'simplexml',
'defaultTagName' => array(parent => child, parent => child)
));

options Mode


Previous Comments:
------------------------------------------------------------------------

[2011-03-24 13:35:28] nadeemshafi9

Description:
------------
hi guys

im using the pear xml serializer but i am running into a problem,

i have a framework for an API which i use to create an array and then
output as xml with xml serializer.

The issue i have run into:

i define a default tag before i create an array

so my array is for example

array(
"a"
"b"
)

both of these will get labeled video in there xml
thats fine

<video>a</video>
<video>b</video>

ok so i have a whole bunch of "videos" with there _attributes set.


inside each video i need multiple media elements

<media x=2>x</media>
<media x=4>x</media>
<media x=5>x</media>

my problem is that you cant add multiple items to an array with the same
Key.

array(
"media" => x,
"media" => x,
"media" => x
)

and if i let it default then the default tag is video


plus i cant set the _attributes of the tag unless i make the value of
the key into an array eg.


array(
"media" => array("_aributes" => array("x" => 1), "mediaValue" =>
"x"),
"media" => array("_aributes" => array("x" => 2), "mediaValue" =>
"x"),
"media" => array("_aributes" => array("x" => 2), "mediaValue" =>
"x")
)


this will give me

<media x=2><mediaValue>x</mediaValue></media>
<media x=4><mediaValue>x</mediaValue></media>
<media x=5><mediaValue>x</mediaValue></media>

at the moment i get

<video>
<media x=2><mediaValue>x</mediaValue></media>
</video>
<video>
<media x=4><mediaValue>x</mediaValue></media>
</video>
<video>
<media x=5><mediaValue>x</mediaValue></media>
</video>

i want to get

<media x=2>x</media>
<media x=4>x</media>
<media x=5>x</media>


any help ? thanks im relay stuck on this one plus my API framework has
constraints because it initializes the serializer at the end and inserts
the array and parses outputs it


even an injection work around would be good but the serializer seems to
convert all tags into html char codes
regards

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedMar 24, '11 at 10:12p
activeMar 24, '11 at 10:12p
posts1
users1
websitepear.php.net

1 user in discussion

Nadeem Shafi: 1 post

People

Translate

site design / logo © 2022 Grokbase