Zend Framework  3.0
Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | List of all members
Xml2Json Class Reference

Class for translating XML to JSON. More...

Static Public Member Functions

static fromXml ($xmlStringContents, $ignoreXmlAttributes=true)
 Converts XML to JSON.
 

Static Public Attributes

static $maxRecursionDepthAllowed = 25
 

Static Protected Member Functions

static getXmlValue ($simpleXmlElementObject)
 Return the value of an XML attribute text or the text between the XML tags.
 
static processXml ($simpleXmlElementObject, $ignoreXmlAttributes, $recursionDepth=0)
 processXml - Contains the logic for fromJson()
 

Detailed Description

Class for translating XML to JSON.

Member Function Documentation

static fromXml (   $xmlStringContents,
  $ignoreXmlAttributes = true 
)
static

Converts XML to JSON.

Converts an XML formatted string into a JSON formatted string.

The caller of this function needs to provide only the first parameter, which is an XML formatted string.

The second parameter, also optional, allows the user to select if the XML attributes in the input XML string should be included or ignored during the conversion.

This function converts the XML formatted string into a PHP array via a recursive function; it then converts that array to json via Json::encode().

NOTE: Encoding native javascript expressions via Zend is not possible.

Deprecated:
by https://github.com/zendframework/zf2/pull/6778
Parameters
string$xmlStringContentsXML String to be converted.
bool$ignoreXmlAttributesInclude or exclude XML attributes in the conversion process.
Returns
string JSON formatted string on success.
Exceptions
Exception\RuntimeExceptionIf the input not a XML formatted string.
static getXmlValue (   $simpleXmlElementObject)
staticprotected

Return the value of an XML attribute text or the text between the XML tags.

In order to allow Zend from XML, we check if the node matches the pattern, and, if so, we return a new Zend instead of a text node.

Parameters
SimpleXMLElement$simpleXmlElementObject
Returns
Expr|string
static processXml (   $simpleXmlElementObject,
  $ignoreXmlAttributes,
  $recursionDepth = 0 
)
staticprotected

processXml - Contains the logic for fromJson()

The logic in this function is a recursive one.

The main caller of this function (fromXml) needs to provide only the first two parameters (the SimpleXMLElement object and the flag for indicating whether or not to ignore XML attributes).

The third parameter will be used internally within this function during the recursive calls.

This function converts a SimpleXMLElement object into a PHP array by calling a recursive function in this class; once all XML elements are stored to a PHP array, it is returned to the caller.

Parameters
SimpleXMLElement$simpleXmlElementObject
bool$ignoreXmlAttributes
int$recursionDepth
Returns
array
Exceptions
Exception\RecursionExceptionif the XML tree is deeper than the allowed limit.

Member Data Documentation

$maxRecursionDepthAllowed = 25
static