Class for translating XML to JSON.
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 | $xmlStringContents | XML String to be converted. |
bool | $ignoreXmlAttributes | Include or exclude XML attributes in the conversion process. |
- Returns
- string JSON formatted string on success.
- Exceptions
-
Exception\RuntimeException | If the input not a XML formatted 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\RecursionException | if the XML tree is deeper than the allowed limit. |