RE: [PEAR] Re: XML_Serializer help adding an attribute to non root element
| From: | Mark Steudel | Date: | Mon, 01 May 2006 15:28:11 +0000 |
| Subject: | RE: [PEAR] Re: XML_Serializer help adding an attribute to non root element | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-23901@lists.php.net to get a copy of this message | ||
Thank you!
-----Original Message-----
From: Ignatius Reilly [mailto:ignatius.reilly@free.fr]
Sent: Saturday, April 29, 2006 6:01 AM
To: pear-general@lists.php.net; Mark Steudel
Subject: [PEAR] Re: XML_Serializer help adding an attribute to non root
element
Yes, the use of options for Serializer is poorly documented..
Have a look at the serializeWithAttributes2.php example in the docs.
Your answer is there.
HTH
Ignatius
Mark Steudel thus spake on 2006-04-28 23:14:
> I'm using XML_serializer to help me turn some arrays into XML, but I'm
> having trouble figuring out how to specify the "type" attribute for
> the campaign element.
>
> === DESIRED XML ====
>
> <company>
> <campaign type="112">
> <conversions>20</conversions>
> <per_conversion>.50</per_conversion>
> <magazines>40</magazines>
> </campaign>
> </company>
>
> === MY STARTING CODE ====
>
> // include class file
> include("Serializer.php");
>
> // create object
> $serializer = new XML_Serializer();
>
> // create array
> $xml = array( 'company' =>
> array( 'campaign' =>
> array( 'conversions' => 20,
> 'per_conversion => .50,
> 'magazine' => 40
> )
> )
> )
>
> // add XML declaration
> $serializer->setOption("addDecl", true);
>
> // indent elements
> $serializer->setOption("indent", " ");
>
> // perform serialization
> $result = $serializer->serialize($xml);
--
PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php