当前位置: 首页>>代码示例>>PHP>>正文


PHP XML_Serializer类代码示例

本文整理汇总了PHP中XML_Serializer的典型用法代码示例。如果您正苦于以下问题:PHP XML_Serializer类的具体用法?PHP XML_Serializer怎么用?PHP XML_Serializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XML_Serializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sitemap_outXML

/**
 * Генерация карты XML.
 */
function sitemap_outXML()
{
    A::$CACHE->page = null;
    require_once "modules/sitemap/sitemap.php";
    $checkeds = getTextOption(getSectionByModule('sitemap'), 'sections');
    $checkeds = !empty($checkeds) ? unserialize($checkeds) : array();
    A::$DB->query("SELECT * FROM " . DOMAIN . "_sections WHERE lang='" . LANG . "' OR lang='all' ORDER BY sort");
    while ($row = A::$DB->fetchRow()) {
        if (in_array($row['id'], $checkeds)) {
            if (function_exists($row['module'] . '_createMap')) {
                $section = DOMAIN . "_" . $row['lang'] . "_" . $row['name'];
                if ($caption = !empty($row['caption_' . LANG]) ? $row['caption_' . LANG] : $row['caption']) {
                    call_user_func($row['module'] . "_createMap", A::$MAINFRAME->treemap, $section, $caption);
                }
            }
        }
    }
    A::$DB->free();
    require_once 'XML/Serializer.php';
    $options = array(XML_SERIALIZER_OPTION_XML_DECL_ENABLED => true, XML_SERIALIZER_OPTION_XML_ENCODING => "utf-8", XML_SERIALIZER_OPTION_INDENT => "\t", XML_SERIALIZER_OPTION_LINEBREAKS => "\n", XML_SERIALIZER_OPTION_ROOT_NAME => 'urlset', XML_SERIALIZER_OPTION_ROOT_ATTRIBS => array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'), XML_SERIALIZER_OPTION_DEFAULT_TAG => 'url');
    $serializer = new XML_Serializer($options);
    $data = array();
    sitemap_itemXML(A::$MAINFRAME->treemap, $data);
    $serializer->serialize($data);
    header("Content-type: text/xml; charset=utf-8");
    die($serializer->getSerializedData());
}
开发者ID:procivam,项目名称:s-mir-new,代码行数:30,代码来源:include.php

示例2: Encode

 public static function Encode($requestObject)
 {
     $soap = "";
     try {
         $writer = new XMLWriter();
         $writer->openMemory();
         $writer->startDocument();
         $writer->setIndent(4);
         $writer->startElement("soap:Envelope");
         $writer->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
         $writer->writeAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
         $writer->writeAttribute("xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/");
         $writer->startElement("soap:Body");
         $options = array(XML_SERIALIZER_OPTION_INDENT => '    ', XML_SERIALIZER_OPTION_LINEBREAKS => "\n", XML_SERIALIZER_OPTION_DEFAULT_TAG => '', XML_SERIALIZER_OPTION_TYPEHINTS => false, XML_SERIALIZER_OPTION_IGNORE_NULL => true, XML_SERIALIZER_OPTION_CLASSNAME_AS_TAGNAME => true);
         $serializer = new XML_Serializer($options);
         $result = $serializer->serialize($requestObject);
         if ($result === true) {
             $xml = $serializer->getSerializedData();
             $xml = str_replace('<>', '', $xml);
             $xml = str_replace('</>', '', $xml);
         }
         $writer->writeRaw($xml);
         $writer->endElement();
         $writer->endElement();
         $writer->endDocument();
         $soap = $writer->flush();
         $soap = str_replace("<?xml version=\"1.0\"?>", "", $soap);
     } catch (Exception $ex) {
         throw new Exception("Error occurred while Soap encoding");
     }
     return $soap;
 }
开发者ID:jobinpankajan,项目名称:WeGive,代码行数:32,代码来源:SOAPEncoder.php

示例3: testNumbered

 /**
  * Test indexed
  */
 public function testNumbered()
 {
     $s = new XML_Serializer($this->options);
     $data = array('foo' => array('atts' => array('one' => 1), 'content' => 'some data', 'bar', 'foo'));
     $s->serialize($data);
     $this->assertEquals('<array><foo one="1">some data<XML_Serializer_Tag>bar</XML_Serializer_Tag><XML_Serializer_Tag>foo</XML_Serializer_Tag></foo></array>', $s->getSerializedData());
 }
开发者ID:pear,项目名称:xml_serializer,代码行数:10,代码来源:Serializer_Option_AttributesContentTest.php

示例4: hook_output

 public static function hook_output($to_print)
 {
     //Construct the object to output
     $object = new StdClass();
     $object->result = $to_print;
     $object->error = Backend::getError();
     $object->notice = Backend::getNotice();
     $object->success = Backend::getSuccess();
     $object->content = Backend::getContent();
     $last = '';
     while (ob_get_level() > self::$ob_level) {
         //Ending the ob_start from __construct
         $last .= ob_get_clean();
     }
     $object->output = $last;
     //Clean up
     Backend::setError();
     Backend::setNotice();
     Backend::setSuccess();
     //Return the XML
     $options = array(XML_SERIALIZER_OPTION_INDENT => "\t", XML_SERIALIZER_OPTION_RETURN_RESULT => true, XML_SERIALIZER_OPTION_DEFAULT_TAG => 'item', XML_SERIALIZER_OPTION_XML_DECL_ENABLED => true, XML_SERIALIZER_OPTION_XML_ENCODING => Controller::$view->charset, XML_SERIALIZER_OPTION_ROOT_NAME => 'XmlResult', XML_SERIALIZER_OPTION_TYPEHINTS => true);
     $serializer = new XML_Serializer($options);
     if ($result = @$serializer->serialize($object)) {
         return $result;
     } else {
         return null;
     }
 }
开发者ID:jrgns,项目名称:backend-php,代码行数:28,代码来源:XmlView.obj.php

示例5: testSleep

 /**
  * Test serializing an object, that supports __sleep
  */
 public function testSleep()
 {
     $obj = new MyClass('foo', 'bar');
     $s = new XML_Serializer($this->options);
     $s->serialize($obj);
     $this->assertEquals('<MyClass><foo>foo</foo></MyClass>', $s->getSerializedData());
 }
开发者ID:pear,项目名称:xml_serializer,代码行数:10,代码来源:Serializer_ObjectsTest.php

示例6: _doResponse

 /**
  * Builds the response
  * 
  * @param type $type
  * @param type $objects
  * @param type $echoResponse
  * @param type $format
  * @return type
  */
 private static function _doResponse($type, $objects, $echoResponse, $format)
 {
     $ret = array();
     $ret['status'] = $type;
     if (is_array($objects)) {
         foreach ($objects as $k => $v) {
             $ret[$k] = $v;
         }
     } else {
         $ret[] = $objects;
     }
     switch ($format) {
         case 'xml':
             require_once 'XML/Serializer.php';
             $options = array("indent" => "    ", "linebreak" => "\n", "typeHints" => false, "addDecl" => true, "encoding" => "UTF-8", "rootName" => "data", "defaultTagName" => "item", "attributesArray" => "_attributes");
             $serializer = new \XML_Serializer($options);
             $rc = $serializer->serialize($ret);
             if ($rc !== TRUE) {
             }
             $ret = $serializer->getSerializedData();
             break;
         case 'json':
         default:
             $ret = json_encode($ret);
             break;
     }
     if ($echoResponse) {
         echo $ret;
     }
     return $ret;
 }
开发者ID:kengoldfarb,项目名称:underscore_libs,代码行数:40,代码来源:_ServiceResponse.php

示例7: testSimpleXML

 /**
  * SimpleXML
  */
 public function testSimpleXML()
 {
     $s = new XML_Serializer($this->options);
     $s->setOption(XML_SERIALIZER_OPTION_MODE, XML_SERIALIZER_MODE_SIMPLEXML);
     $s->serialize(array('foo' => array(1, 2, 3), 'bar' => array(1, 2, 3)));
     $this->assertEquals('<array><foo>1</foo><foo>2</foo><foo>3</foo><bar>1</bar><bar>2</bar><bar>3</bar></array>', $s->getSerializedData());
 }
开发者ID:pear,项目名称:xml_serializer,代码行数:10,代码来源:Serializer_Option_ModeTest.php

示例8: serialize

 /**
  * @param $data
  * @param $clear_data Clear the data variable
  * @return unknown_type
  */
 function serialize(&$data, $clear_data = false, $rootName = 'root', $addDecl = TRUE)
 {
     //serialize an array
     $serializer_options = array('addDecl' => $addDecl, 'encoding' => 'ISO-8859-1', 'indent' => '  ', 'rootName' => $rootName, 'defaultTagName' => 'item');
     // Instantiate the serializer with the options
     $Serializer = new XML_Serializer($serializer_options);
     // Serialize the data structure
     try {
         //$this->logger->debug("Serializing into XML:".print_r($data, true));
         $status = $Serializer->serialize($data);
         //Clear the original data if set
         if ($clear_data) {
             $data = array();
         }
         //$this->logger->debug("Serialization Status: ".var_export($status, true));
         // Check whether serialization worked
         if (PEAR::isError($status)) {
             $this->logger->error("Error in XML serialization: " . var_export($status, true));
             die($status->getMessage());
         }
         //echo "here";//var_dump($Serializer);
         //echo "Status: $status";
     } catch (Exception $e) {
         $this->logger->error("Exception in serialization: " . var_export($e, true));
     }
     // Display the XML document
     return $Serializer->getSerializedData();
 }
开发者ID:rajnishp,项目名称:bjs,代码行数:33,代码来源:Xml.php

示例9: testUri

 /**
  * Simple namespace
  */
 public function testUri()
 {
     $s = new XML_Serializer($this->options);
     $s->setOption(XML_SERIALIZER_OPTION_NAMESPACE, array('foo', 'http://pear.php.net/XML_Serializer/foo'));
     $s->serialize(array('foo' => 'bar'));
     $this->assertEquals('<foo:array xmlns:foo="http://pear.php.net/XML_Serializer/foo"><foo:foo>bar</foo:foo></foo:array>', $s->getSerializedData());
 }
开发者ID:pear,项目名称:xml_serializer,代码行数:10,代码来源:Serializer_Option_NamespaceTest.php

示例10: go

 public static function go($json, $attr = true, $rootAttr = array())
 {
     //----------------------------------------------------------
     $options = array();
     $options['addDecl'] = TRUE;
     $options['encoding'] = 'UTF-8';
     $options['indent'] = '  ';
     $options['rootName'] = 'root';
     $options['mode'] = 'simplexml';
     if ($attr) {
         $options['scalarAsAttributes'] = true;
     }
     $options['cdata'] = true;
     $options['rootAttributes'] = $rootAttr;
     //----------------------------------------------------------
     $serializer = new XML_Serializer($options);
     $obj = json_decode($json);
     //----------------------------------------------------------
     if ($serializer->serialize($obj)) {
         $xml = $serializer->getSerializedData();
         return $xml;
     } else {
         return null;
     }
 }
开发者ID:awwthentic1234,项目名称:hey,代码行数:25,代码来源:JSON2XML.php

示例11: save

 function save($data)
 {
     require_once 'XML/Serializer.php';
     $xmlEngine = new XML_Serializer();
     $xmlresult = $xmlEngine->serialize($data);
     $locale = AMP_LOCAL_PATH . '/custom/' . $this->AMP_Object_Type . '_' . $this->DataDescription . '.xml';
     $this->saveFile($xmlEngine->getSerializedData(), $locale);
 }
开发者ID:radicaldesigns,项目名称:amp,代码行数:8,代码来源:XMLFields.inc.php

示例12: testMixed

 /**
  * Test setting mixed default tags
  */
 public function testMixed()
 {
     $s = new XML_Serializer($this->options);
     $data = array('foos' => array(1, 2), 'bars' => array(1, 2), 'test');
     $s->setOption(XML_SERIALIZER_OPTION_DEFAULT_TAG, array('foos' => 'foo', '#default' => 'tag'));
     $s->serialize($data);
     $this->assertEquals('<array><foos><foo>1</foo><foo>2</foo></foos><bars><tag>1</tag><tag>2</tag></bars><tag>test</tag></array>', $s->getSerializedData());
 }
开发者ID:pear,项目名称:xml_serializer,代码行数:11,代码来源:Serializer_Option_DefaultTagTest.php

示例13: build

 public static function build($rootNode, $vals = null)
 {
     $xsz = new XML_Serializer(array('rootName' => $rootNode, 'mode' => 'simplexml'));
     $xsz->serialize($vals);
     $xml = $xsz->getSerializedData();
     Nimble::log($xml, PEAR_LOG_DEBUG);
     return $xml;
 }
开发者ID:sbeam,项目名称:nimble,代码行数:8,代码来源:init.php

示例14: testId

 /**
  * Declaration and ID and system reference
  */
 public function testId()
 {
     $s = new XML_Serializer($this->options);
     $s->setOption(XML_SERIALIZER_OPTION_DOCTYPE_ENABLED, true);
     $s->setOption(XML_SERIALIZER_OPTION_DOCTYPE, array('uri' => 'http://pear.php.net/dtd/package-1.0', 'id' => '-//PHP//PEAR/DTD PACKAGE 1.0'));
     $s->serialize('string');
     $this->assertEquals('<!DOCTYPE string PUBLIC "-//PHP//PEAR/DTD PACKAGE 1.0" "http://pear.php.net/dtd/package-1.0"><string>string</string>', $s->getSerializedData());
 }
开发者ID:quangbt2005,项目名称:vhost-kis,代码行数:11,代码来源:Serializer_Option_DocType_TestCase.php

示例15: testEncoding

 /**
  * Add encoding
  */
 public function testEncoding()
 {
     $s = new XML_Serializer($this->options);
     $s->setOption(XML_SERIALIZER_OPTION_XML_DECL_ENABLED, true);
     $s->setOption(XML_SERIALIZER_OPTION_XML_ENCODING, 'ISO-8859-1');
     $s->serialize('string');
     $this->assertEquals('<?xml version="1.0" encoding="ISO-8859-1"?><string>string</string>', $s->getSerializedData());
 }
开发者ID:quangbt2005,项目名称:vhost-kis,代码行数:11,代码来源:Serializer_Option_XmlDeclaration_TestCase.php


注:本文中的XML_Serializer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。