\XgapVarConvertXml

Codificación de variables PHP en formato XML.

Importante: No usar con variables que contengan referencias circulares o componentes de tipo resource.

El formato del XML generado está definido por el siguiente DTD:

<!-- Data -->
<!ELEMENT d (v|s)>

<!-- Valor simple -->
<!ELEMENT v (#PCDATA)>
<!-- t: tipo de datos = NULL|boolean|integer|double|string -->
<!ATTLIST v
  t NMTOKEN #REQUIRED>

<!-- Struct (valor compuesto) -->
<!ELEMENT s (i*)>
<!-- t: tipo = array | object -->
<!ATTLIST s
  t (a|o) #REQUIRED>

<!-- Item de estructura -->
<!ELEMENT i (v|s)>
<!-- n: Nombre -->
<!ATTLIST i
  n CDATA #REQUIRED>

Los valores simples se convierten con el siguiente formato:

  • NULL ::- null
  • TRUE ::- true
  • FALSE ::- false
  • 1 ::- 1
  • 1.2 ::- 1.2
  • 'a' ::- a

Ejemplos: $conv = new XgapVarConvertXml();

$xml = $conv->encode(TRUE); // $xml === 'true'

$xml = $conv->encode(array()); // $xml === ''

$xml = $conv->encode(array( 'a1' => (object)array('prop1' => 1, 'prop2' => 2), 'a2' => 3.14, 'x y z', '_ID#1' => NULL, array(15, 16) )); // $xml === ' // // // // 1 // 2 // // // 3.14 // x y z // null // // // 15 // 16 // // // // '

Summary

Methods
Properties
Constants
encode()
decode()
getCharacterEncoding()
formatName()
No public properties found
FORMAT_NAME
writeSimple()
writeArray()
writeObject()
write()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

FORMAT_NAME

FORMAT_NAME

Methods

encode()

encode(mixed  $var) : mixed

Codifica <var>$var</var> en XML.

Parameters

mixed $var

la variable a codificar, dada en la codificación de caracteres interna de PHP

Throws

\ExcepcionXGAP

si hay un error durante la operación

Returns

mixed —

el valor codificado en XML, con la codificación de caracteres indicada por {@link iXgapVarConvert::getCharacterEncoding()}

decode()

decode(string  $encoded) : mixed

Transforma en una variable PHP un documento XML dado en el formato generado por {@link iXgapVarConvert::encode()}.

Parameters

string $encoded

XML, con la codificación de caracteres indicada por {@link self::getCharacterEncoding()}

Throws

\ExcepcionXGAP

si hay un error durante la operación

Returns

mixed —

el valor decodificado, usando la codificación de caracteres interna de PHP

getCharacterEncoding()

getCharacterEncoding() : string

Permite consultar la codificación de caracteres que tiene el valor de retorno de {@link iXgapVarConvert::encode()} y el parámetro <var>$encoded</var> de {@link iXgapVarConvert::decode()}.

Returns

string

formatName()

formatName() : string

Nombre identificatorio para el formato con que opera la implementación.

Returns

string

writeSimple()

writeSimple(\XMLWriter  $xmlwriter, mixed  $var, string  $type) 

Genera el XML para un valor simple.

Parameters

\XMLWriter $xmlwriter
mixed $var
string $type

writeArray()

writeArray(\XMLWriter  $xmlwriter, array  $var) 

Parameters

\XMLWriter $xmlwriter
array $var

writeObject()

writeObject(\XMLWriter  $xmlwriter, object  $var) 

Parameters

\XMLWriter $xmlwriter
object $var

write()

write(\XMLWriter  $xmlwriter, mixed  $var) 

Parameters

\XMLWriter $xmlwriter
mixed $var