[Php-it] SimpleXML vs XHTML

Andrea Franceschini therealmorpheu5 at gmail.com
Thu Mar 15 10:46:27 CET 2007


Allora, partendo dall'idea che XML è un linguaggio facile da leggere
dagli umani e considerato che il codice XHTML generato dalla mia
applicazione fa un bel po' pena per quanto riguarda indentazioni e
annidamenti, ho pensato di buttare l'output XHTML della mia
applicazione dentro un oggetto SimpleXML e poi estrarlo con il metodo
asXML() che genera del codice pulitopulito e facile da leggere.

Solo che SimpleXML si rifiuta di parsare le htmlentities tipo © e
simili, chissà perché. L'errore particolare nel mio caso è

Warning: SimpleXMLElement::__construct()
[function.SimpleXMLElement---construct]: Entity: line 19: parser error
: Entity 'copy' not defined in
/home/morpheu5/web/carbon/core/class.xml.php on line 47

Warning: SimpleXMLElement::__construct()
[function.SimpleXMLElement---construct]: <meta name="copyright"
content="&copy; 2007 by Carbon Team" /> in
/home/morpheu5/web/carbon/core/class.xml.php on line 47

Warning: SimpleXMLElement::__construct()
[function.SimpleXMLElement---construct]: ^ in
/home/morpheu5/web/carbon/core/class.xml.php on line 47

Warning: SimpleXMLElement::__construct()
[function.SimpleXMLElement---construct]: Entity: line 67: parser error
: Entity 'copy' not defined in
/home/morpheu5/web/carbon/core/class.xml.php on line 47

Warning: SimpleXMLElement::__construct()
[function.SimpleXMLElement---construct]: <span>&copy; 2007 Carbon Team
- all rights reserved - lefts and other directi in
/home/morpheu5/web/carbon/core/class.xml.php on line 47

Warning: SimpleXMLElement::__construct()
[function.SimpleXMLElement---construct]: ^ in
/home/morpheu5/web/carbon/core/class.xml.php on line 47

Ora, mi rifiuto di credere che SimpleXML non riesca a fare il parsing
di un documento XHTML ben formato di cui dichiaro DTD e namespace
correttamente e in cui includo perfino l'intestazione XML di rito:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Qualche idea?


More information about the Php-it mailing list