I'm using this XML to Json Zend module.
The problem is I can receive a bad formated XML string from the webservice that I'm connected. When this XML is processed at the fromXml Zend method it throws a warning.
So I would like to validate the XML before call the fromXml function. How can I know if a XML is valid? Prefereable using Zend?
I tried to use the code as following but I hadn't sucess yet: (this XML string works when using the fromXml)
<?php
$xml1 = 'asdf';
$xml2 = '<?xml version="1.0" encoding="iso-8859-1" ?>
<sroxml>
<version>1.0</version>
<quantity>1</quantity>
<SearchType>Objetcs List</SearchType>
<ResultType>All events</ResultType>
<object>
<number>AA299100299BB</number>
<event>
<type>BDI</type>
<status>01</status>
<date>07/01/2013</date>
<hour>12:12</hour>
<description>Received</description>
<receiver>MARY WILLIAN </receiver>
<document>AA. 111639676 </document>
<comment> </comment>
<local>Some local</local>
<code>11151970</code>
<city>Some City</city>
<uf>AB</uf>
<sto>11102272</sto>
</event>
</object>
</sroxml>';
$validator = new DOMDocument();
$validator->loadXML($xml2, LIBXML_DTDLOAD|LIBXML_DTDVALID|LIBXML_ERR_WARNING |LIBXML_DTDATTR);
echo "<br>testing<pre>"; var_dump($validator->validate()); echo "</pre><br>";