PEAR, XML

簡単な例

|php|
<?php
require_once 'XML/Unserializer.php';

$options = array(  
  "indent"    => " ",  
  "linebreak" => "\n",  
  "typeHints" => false,  
  "addDecl"   => true,  
  "encoding"  => "UTF-8",  
  "rootName"  => "feed",  
  XML_SERIALIZER_OPTION_ROOT_ATTRIBS => array('xmlns' => 'http://www.w3.org/2005/Atom'),  
  //"defaultTagName" => "info",  
  XML_SERIALIZER_OPTION_ATTRIBUTES_KEY => '_attributes',  
  XML_SERIALIZER_OPTION_CONTENT_KEY => '_content',  
);  
$serializer = new XML_Serializer($options);

$atom = array(  
  "title"   => "atyks's blog",  
  "link"    => array(  
    '_attributes' => array('href' => Router::url("/", true)),  
    '_content'    => ''  
  ),  
  "updated" => date("Y-m-d\TH:i:s"),  
  "author"  => "atyks",  
  "entry"   => $data["entry"],  
);

$serializer->serialize($atom);  
$xml = $serializer->getSerializedData();

?>

||<

tips

属性を指定するには、XML_SERIALIZER_OPTION_ATTRIBUTES_KEYとXML_SERIALIZER_OPTION_CONTENT_KEYを使う