[TYPO3-core] RFC: Bug #9217: typo3ajax::renderAsXML does not always render XML

Steffen Kamper info at sk-typo3.de
Sun Aug 24 13:21:16 CEST 2008


Francois Suter schrieb:
> Hi Steffen,
> 
>> you're right, open is for URI and XML for string.
>> Important is the setParserProperty, so here is the working example:
> 
> I've finally got the following code working:
> 
> $xml = '<test><foo>dummy</bar></test>';
> $reader = new XMLReader();
> $reader->XML($xml);
> $reader->setParserProperty(XMLReader::VALIDATE, true);
> if ($reader->isValid()) {
>     echo 'OK';
> }
> else {
>     echo 'KO';
> }
> 
> but I'm pretty puzzled, because it returns OK, although the XML is 
> obviously not valid. simplexml_load_string() returns false in such a 
> case...
> 
> Cheers
> 

Hi Francois,

yes, it's like exploring an undocumented feature :-) The docs are really 
spare.

I tested a while and found some infos about.
$reader->setParserProperty(XMLReader::VALIDATE, true); Loads a DTD and 
validate against. As there is no DTD it always returns true, even if XML 
isn't valid
With this you get the error:
while ($reader->read()) {
}
The problem is that there is not a simple boolean flag like with 
simplexml_load_string(), So i would suggest to use simplexml_load_string 
  for now. But some tests with different charsets and CDATA has to be 
done as i'm not sure if it validates correct. I will dig deeper with 
XMLReader as it's interesting for ExtensionManager for saving 
ressources, and if i found a better method for valid check i will post it.

Anyway the php-warnings has to be suppressed, using @ or manipulating 
error_reporting as both methods throw warnings with not valid XML.

vg Steffen


More information about the TYPO3-team-core mailing list