PHP 클래스 XML_Serializer

this class can be used in two modes: 1. create an XML document from an array or object that is processed by other applications. That means, you can create a RDF document from an array in the following format: $data = array( "channel" => array( "title" => "Example RDF channel", "link" => "http://www.php-tools.de", "image" => array( "title" => "Example image", "url" => "http://www.php-tools.de/image.gif", "link" => "http://www.php-tools.de" ), array( "title" => "Example item", "link" => "http://example.com" ), array( "title" => "Another Example item", "link" => "http://example.org" ) ) ); to create a RDF document from this array do the following: require_once 'XML/Serializer.php'; $options = array( "indent" => "\t", // indent with tabs "linebreak" => "\n", // use UNIX line breaks "rootName" => "rdf:RDF", // root tag "defaultTagName" => "item" // tag for values with numeric keys ); $serializer = new XML_Serializer($options); $rdf = $serializer->serialize($data); You will get a complete XML document that can be processed like any RDF document. 2. this classes can be used to serialize any data structure in a way that it can later be unserialized again. XML_Serializer will store the type of the value and additional meta information in attributes of the surrounding tag. This meat information can later be used to restore the original data structure in PHP. If you want XML_Serializer to add meta information to the tags, add "typeHints" => true to the options array in the constructor. Future versions of this package will include an XML_Unserializer, that does the unserialization automatically for you.
저자: Stephan Schmidt ([email protected])
상속: extends PEAR
파일 보기 프로젝트 열기: sourcefabric/newscoop 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$_defaultOptions array Default options for the serialization
$_knownOptions array List of all available options
$_serializedData string Serialized representation of the data
$_tagDepth integer Current tag depth
$options array Options for the serialization

공개 메소드들

메소드 설명
XML_Serializer ( mixed $options = null ) Constructor
_createXMLTag ( array $tag, boolean $firstCall = true ) : string create a tag from an array this method awaits an array in the following format array( 'qname' => $tagName, 'attributes' => array(), 'content' => $content, // optional 'namespace' => $namespace // optional 'namespaceUri' => $namespaceUri // optional )
_getDefaultTagname ( string $parent ) : string get the name of the default tag.
_serializeArray ( &$array, string $tagName = null, array $attributes = [] ) : string serialize an array
_serializeObject ( &$object, string $tagName = null, array $attributes = [] ) : string serialize an object
_serializeValue ( mixed $value, string $tagName = null, array $attributes = [] ) : string serialize any value
apiVersion ( ) : string Return the package version number
getSerializedData ( ) : string get the result of the serialization
resetOptions ( ) : void Reset all options to default options
serialize ( mixed $data, array $options = null ) : boolean serialize data
setOption ( string $name, mixed $value ) : void Set an option
setOptions ( array $options ) : void Sets several options at once

메소드 상세

XML_Serializer() 공개 메소드

Constructor
public XML_Serializer ( mixed $options = null )
$options mixed array containing options for the serialization

_createXMLTag() 공개 메소드

create a tag from an array this method awaits an array in the following format array( 'qname' => $tagName, 'attributes' => array(), 'content' => $content, // optional 'namespace' => $namespace // optional 'namespaceUri' => $namespaceUri // optional )
public _createXMLTag ( array $tag, boolean $firstCall = true ) : string
$tag array tag definition
$firstCall boolean whether or not this is the first call
리턴 string $string XML tag

_getDefaultTagname() 공개 메소드

The name of the parent tag needs to be passed as the default name can depend on the context.
public _getDefaultTagname ( string $parent ) : string
$parent string name of the parent tag
리턴 string default tag name

_serializeArray() 공개 메소드

serialize an array
public _serializeArray ( &$array, string $tagName = null, array $attributes = [] ) : string
$tagName string name of the root tag
$attributes array attributes for the root tag
리턴 string $string serialized data

_serializeObject() 공개 메소드

serialize an object
public _serializeObject ( &$object, string $tagName = null, array $attributes = [] ) : string
$tagName string tag name
$attributes array attributes
리턴 string $string serialized data

_serializeValue() 공개 메소드

This method checks for the type of the value and calls the appropriate method
public _serializeValue ( mixed $value, string $tagName = null, array $attributes = [] ) : string
$value mixed tag value
$tagName string tag name
$attributes array attributes
리턴 string

apiVersion() 공개 메소드

Return the package version number
public apiVersion ( ) : string
리턴 string the version number of XML_Serializer

getSerializedData() 공개 메소드

get the result of the serialization
public getSerializedData ( ) : string
리턴 string serialized XML

resetOptions() 공개 메소드

Reset all options to default options
public resetOptions ( ) : void
리턴 void

serialize() 공개 메소드

serialize data
public serialize ( mixed $data, array $options = null ) : boolean
$data mixed data to serialize
$options array options array
리턴 boolean true on success, pear error on failure

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

setOptions() 공개 메소드

You can use this method if you do not want to set all options in the constructor.
public setOptions ( array $options ) : void
$options array options array
리턴 void

프로퍼티 상세

$_defaultOptions 공개적으로 프로퍼티

Default options for the serialization
public array $_defaultOptions
리턴 array

$_knownOptions 공개적으로 프로퍼티

List of all available options
public array $_knownOptions
리턴 array

$_serializedData 공개적으로 프로퍼티

Serialized representation of the data
public string $_serializedData
리턴 string

$_tagDepth 공개적으로 프로퍼티

Current tag depth
public int $_tagDepth
리턴 integer

$options 공개적으로 프로퍼티

Options for the serialization
public array $options
리턴 array