Zend\Json\Json::fromXml
fromXml - Converts XML to JSON
Converts a XML formatted string into a JSON formatted string. The value returned will be a string in JSON format. The caller of this function needs to provide only the first parameter, which is an XML formatted String. The second parameter is optional, which lets the user to select if the XML attributes in the input XML string should be included or ignored in xml2json conversion. This function converts the XML formatted string into a PHP array by calling a recursive (protected static) function in this class. Then, it converts that PHP array into JSON by calling the "encode" static function. NOTE: Encoding native javascript expressions via Zend\Json\Expr is not possible.
Signature
public function fromXml(string
$xmlStringContents,
[bool
$ignoreXmlAttributes = true] )
Parameters
$xmlStringContents
— string- XML String to be converted
$ignoreXmlAttributes
— object- Include or exclude XML attributes in
the xml2json conversion process.
Returns
- mixed
- - JSON formatted string on success
Errors/Exceptions
-
RuntimeException
- if the input not a XML formatted string