Re: XML_Serializer help adding an attribute to non root element

From: Date: Sat, 29 Apr 2006 13:01:06 +0000
Subject: 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-23887@lists.php.net to get a copy of this message
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);


« previous php.pear.general (#23887) next »