setOption() 공개 메소드

You can use this method if you do not want to set all options in the constructor.
public setOption ( string $name, mixed $value ) : void
$name string option name
$value mixed option value
리턴 void
 /**
  * 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());
 }
 /**
  * Test object
  */
 public function testNumberedObjects()
 {
     $s = new XML_Serializer($this->options);
     $s->setOption(XML_SERIALIZER_OPTION_CLASSNAME_AS_TAGNAME, true);
     $s->setOption(XML_SERIALIZER_OPTION_TAGMAP, array('stdClass' => 'foo'));
     $s->serialize(array(new stdClass(), new stdClass()));
     $this->assertEquals('<array><foo /><foo /></array>', strtolower($s->getSerializedData()));
 }
 /**
  * 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());
 }
 /**
  * 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());
 }
 /**
  * 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());
 }
 /**
  * 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());
 }
    /**
     * Indent with tabs
     */
    public function testTabs()
    {
        $s = new XML_Serializer($this->options);
        $s->setOption(XML_SERIALIZER_OPTION_INDENT, "\t");
        $s->serialize(array('foo' => 'bar'));
        $this->assertEquals('<array>
	<foo>bar</foo>
</array>', $s->getSerializedData());
    }
예제 #8
0
파일: Views.php 프로젝트: hbasria/pjango
 function ws_model_id($request, $model = false, $id = false)
 {
     $resArr = array();
     if (class_exists($model)) {
         if ($request->_request_method == HttpRequest::REQUEST_METHOD_GET) {
             $obj = Doctrine::getTable($model)->find($id);
             if ($obj) {
                 $resArr['data'] = $obj->toArray();
             }
         } elseif ($request->_request_method == HttpRequest::REQUEST_METHOD_POST) {
             $obj = Doctrine::getTable($model)->find($id);
             if (!$obj) {
                 $obj = new $model();
             }
             try {
                 $obj->fromArray($request->_request_data);
                 $obj->save();
                 $resArr['data'] = $obj->toArray();
                 $resArr['code'] = "200";
                 $resArr['message'] = "OK";
             } catch (Exception $e) {
                 $resArr['code'] = "304";
                 $resArr['error']['message'] = "Not Modified";
             }
         } else {
             $resArr['code'] = "400";
             $resArr['message'] = "Bad Request";
             $resArr['error']['message'] = "Bad Request";
         }
     } else {
         $resArr['code'] = "404";
         $resArr['message'] = "Not Found";
         $resArr['error']['message'] = $model . ' Not Found';
     }
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     header("Content-type: text/xml; charset=utf-8");
     if ($request->is_ajax()) {
         echo json_encode($resArr);
     } else {
         require_once 'XML/Serializer.php';
         $serializer = new XML_Serializer();
         $serializer->setOption(XML_SERIALIZER_OPTION_INDENT, '    ');
         $serializer->setOption(XML_SERIALIZER_OPTION_ROOT_NAME, 'RestWS');
         $serializer->setOption(XML_SERIALIZER_OPTION_XML_ENCODING, 'UTF-8');
         $serializer->setOption(XML_SERIALIZER_OPTION_LINEBREAKS, "\n");
         $serializer->setOption(XML_SERIALIZER_OPTION_DEFAULT_TAG, 'item');
         $serializer->setOption(XML_SERIALIZER_OPTION_CDATA_SECTIONS, FALSE);
         $result = $serializer->serialize($resArr);
         $xml = $serializer->getSerializedData();
         echo $xml;
     }
 }
$options = array("indent" => '    ', "linebreak" => "\n");
$serializer = new XML_Serializer($options);
$object = new stdClass();
$object->foo = 'bar';
$object->bar = null;
$array = array('foo' => 'bar', 'bar' => null);
$result = $serializer->serialize($object);
if ($result === true) {
    echo "<pre>";
    echo htmlentities($serializer->getSerializedData());
    echo "</pre>";
}
$result = $serializer->serialize($array);
if ($result === true) {
    echo "<pre>";
    echo htmlentities($serializer->getSerializedData());
    echo "</pre>";
}
$serializer->setOption('ignoreNull', true);
$result = $serializer->serialize($object);
if ($result === true) {
    echo "<pre>";
    echo htmlentities($serializer->getSerializedData());
    echo "</pre>";
}
$result = $serializer->serialize($array);
if ($result === true) {
    echo "<pre>";
    echo htmlentities($serializer->getSerializedData());
    echo "</pre>";
}
예제 #10
0
<?php

/**
 * XML Serializer example
 *
 * This example makes use of the CData sections option
 *
 * @author  Stephan Schmidt <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'XML/Serializer.php';
$serializer = new XML_Serializer();
$serializer->setOption(XML_SERIALIZER_OPTION_INDENT, '    ');
$serializer->setOption(XML_SERIALIZER_OPTION_DEFAULT_TAG, 'item');
$serializer->setOption(XML_SERIALIZER_OPTION_CDATA_SECTIONS, true);
$data = array('foo' => 'This is some text...', 'bar' => '& even more text...', 'test' => array('Foo', 'Foo & bar'));
$result = $serializer->serialize($data);
if ($result === true) {
    $xml = $serializer->getSerializedData();
    echo '<pre>';
    echo htmlspecialchars($xml);
    echo '</pre>';
} else {
    $result->getMessage();
    exit;
}
<?php

/**
 * This shows that XML_Serializer is able to work with
 * empty arrays
 *
 * @author Stephan Schmidt <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'XML/Serializer.php';
$data = array(array('name' => 'Superman', 'age' => 34, 'realname' => 'Clark Kent'), array('name' => 'Batman', 'age' => 32, 'realname' => 'Bruce Wayne'), 'villain' => array('name' => 'Professor Zoom', 'age' => 'unknown', 'realname' => 'Hunter Zolomon'));
$serializer = new XML_Serializer();
$serializer->setOption(XML_SERIALIZER_OPTION_INDENT, '    ');
$serializer->setOption(XML_SERIALIZER_OPTION_DEFAULT_TAG, 'hero');
$serializer->serialize($data);
echo '<pre>';
echo "Default behaviour:\n";
echo htmlspecialchars($serializer->getSerializedData());
echo '</pre>';
$serializer->setOption(XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES, true);
$serializer->serialize($data);
echo '<pre>';
echo "XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES = true:\n";
echo htmlspecialchars($serializer->getSerializedData());
echo '</pre>';
$serializer->setOption(XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES, array('hero' => array('name', 'age'), 'villain' => array('realname')));
$serializer->serialize($data);
echo '<pre>';
echo "XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES is an array:\n";
echo htmlspecialchars($serializer->getSerializedData());
echo '</pre>';
예제 #12
0
<?php

require_once 'XML/Serializer.php';
$citation = array('book' => array('author' => array(array('John Doe', 'attributes' => array('id' => 1)), array('Bob Jones', 'attributes' => array('id' => 2))), 'title' => 'Title of the book'));
$s = new XML_Serializer();
$s->setOption(XML_SERIALIZER_OPTION_INDENT, '    ');
$s->setOption(XML_SERIALIZER_OPTION_ATTRIBUTES_KEY, 'attributes');
$s->setOption(XML_SERIALIZER_OPTION_MODE, XML_SERIALIZER_MODE_SIMPLEXML);
$s->serialize($citation);
echo '<pre>';
echo htmlentities($s->getSerializedData());
echo '</pre>';
예제 #13
0
파일: UPS.php 프로젝트: alachaum/timetrex
 function time_in_transit()
 {
     $this->service = 'time in transit';
     $serializer = new XML_Serializer();
     $serializer->setOption('linebreak', '');
     $serializer->setOption('addDecl', true);
     $serializer->setOption('rootName', 'TimeInTransitRequest');
     $root_attr['xml:lang'] = 'en-US';
     $serializer->setOption('rootAttributes', $root_attr);
     $customercontext = 'Request generated by PHP PEAR Services_UPS Package by Tim Batz';
     $xml_array['Request']['TransactionReference']['CustomerContext'] = $customercontext;
     $xml_array['Request']['TransactionReference']['XpciVersion'] = '1.0001';
     $xml_array['Request']['RequestAction'] = 'TimeInTransit';
     $xml_array['TransitFrom']['AddressArtifactFormat']['PoliticalDivision3'] = '';
     $xml_array['TransitFrom']['AddressArtifactFormat']['PoliticalDivision2'] = '';
     $xml_array['TransitFrom']['AddressArtifactFormat']['PoliticalDivision1'] = '';
     $xml_array['TransitFrom']['AddressArtifactFormat']['CountryCode'] = '';
     $xml_array['TransitFrom']['AddressArtifactFormat']['PostcodePrimaryLow'] = '';
     $xml_array['TransitTo']['AddressArtifactFormat']['PoliticalDivision3'] = '';
     $xml_array['TransitTo']['AddressArtifactFormat']['PoliticalDivision2'] = '';
     $xml_array['TransitTo']['AddressArtifactFormat']['PoliticalDivision1'] = '';
     $xml_array['TransitTo']['AddressArtifactFormat']['CountryCode'] = '';
     $xml_array['TransitTo']['AddressArtifactFormat']['PostcodePrimaryLow'] = '';
     $xml_array['TransitTo']['AddressArtifactFormat']['ResidentialAddressIndicator'] = '';
     $xml_array['PickupDate'] = '';
     $xml_array['ShipmentWeight']['UnitOfMeasurement']['Code'] = '';
     // LBS/KGS
     $xml_array['ShipmentWeight']['UnitOfMeasurement']['Description'] = '';
     // Pounds/Kilograms
     $xml_array['ShipmentWeight']['Weight'] = '';
     $xml_array['TotalPackagesInShipment'] = '';
     // default 1
     $xml_array['InvoiceLineTotal']['CurrencyCode'] = '';
     $xml_array['InvoiceLineTotal']['MonetaryValue'] = '';
     $xml_array['DocumentsOnlyIndicator'] = '';
     // set or not
     $xml_array['MaximumListSize'] = '';
     // default 35 / 1-50
     /*
     $msg  = 'At least one parameter is needed validate an address!';
     PEAR::raiseError($msg, 0, PEAR_ERROR_DIE);
     */
     $serializer->serialize($xml_array);
     $this->request = $serializer->getSerializedData();
 }
예제 #14
0
    $_POST['cmb_clib_version'] = '';
}
$libc_version = $_POST['cmb_clib_version'];
$config->set_target_options($_POST['cmb_arch'], $_POST['cmb_variant'], $_POST['rd_abi'], $_POST['cmb_endian'], $_POST['cmb_float']);
$config->set_toolchain_options($_POST['chk_sysroot'], $_POST['chk_build_shared_lib'], 'unknown');
$config->set_os($_POST['cmb_os'], $_POST['cmb_kernel_version']);
$config->set_gmp_mpfr($_POST['chk_gmp_mpfr'], $_POST['cmb_gmp'], $_POST['cmb_mpfr']);
$config->set_binutils($_POST['cmb_binutils'], $_POST['chk_libbfd'], $_POST['chk_libiberty']);
$config->set_cc($_POST['cmb_cc'], $_POST['chk_cpp'], $_POST['chk_fortran'], $_POST['chk_java']);
$config->set_clib($_POST['cmb_clib'], $libc_version, $_POST['cmb_thread']);
$config->set_tools($_POST['chk_libelf'], $_POST['chk_sstrip']);
$config->set_debug($_POST['chk_gdb'], $_POST['chk_dmalloc'], $_POST['chk_duma'], $_POST['chk_ltrace'], $_POST['chk_strace']);
// add XML declaration
//$serializer->setOption("addDecl", true);
// indent elements
$serializer->setOption("indent", "    ");
// set name for root element
$serializer->setOption("rootName", "ToolchainConfig");
$serializer->setOption("classAsTagName", "true");
$serializer->serialize($config);
//print $serializer->getSerializedData();
// Giving the toolchain configuration file name
$manufacturer = 'unknown';
$arch = $_POST['cmb_arch'];
$variant = $_POST['cmb_variant'];
$endianness = $_POST['cmb_endian'];
$abi = $_POST['rd_abi'];
$libc = $_POST['cmb_clib'];
/////////////////////////////////////////////////////////////////////
// The architecture part of the toolchain tuple
if ($arch == 'x86') {
예제 #15
0
require_once "Connections/freedomrising.php";
require_once "XML/Serializer.php";
$dbcon->SetFetchMode(ADODB_FETCH_ASSOC);
$user_sql = "SELECT * FROM phplist_user_user";
$attribute_sql = "SELECT * FROM phplist_user_user_attribute LEFT JOIN phplist_user_attribute ON phplist_user_user_attribute.attributeid = phplist_user_attribute.id";
$list_sql = "SELECT * FROM phplist_listuser";
$user_rs = $dbcon->Execute($user_sql);
$attr_rs = $dbcon->Execute($attribute_sql);
$list_rs = $dbcon->Execute($list_sql);
while ($row = $user_rs->FetchRow()) {
    $subdata[$row['id']] = $row;
}
while ($row = $attr_rs->FetchRow()) {
    $attrname = str_replace(" ", "_", $row['name']);
    $subdata[$row['userid']][$attrname] = $row['value'];
}
while ($row = $list_rs->FetchRow()) {
    $subdata[$row['userid']]['list'][] = $row['listid'];
}
$serializer = new XML_Serializer();
$serializer->setOption("addDecl", true);
$serializer->setOption("indent", "    ");
$serializer->setOption("rootName", "user");
//$serializer->setOption( "defaultTagName", "user" );
$serializer->setOption("mode", "simplexml");
$result = $serializer->serialize($subdata);
header('Content-Type: text/xml');
if ($result === true) {
    $xmlout = $serializer->getSerializedData();
}
print $xmlout;