Source Rally PHP Community Scripts .. Sign up .. Login
---

libxml was created by XML pedants. It throws a FATAL error for any undefined entity.
Real data notes are created by XML ignoramuses (i.e., anybody but you and I).
They use entities that might not be defined. Browers cope by ignoring them.

php's XSLT is the short route from data to html, but it goes through the libxml choke point. What to do? After too much effort, I found the simple solution below.
Add to favourites       Subscribe comments       Copy code       Bookmark
function hideEntities($data) { 
        return str_replace("&", "&", $data); 
}


// Sample use
    $xmlfilename = "...";
    $proc = new XSLTProcessor();
    $xmldoc = new DOMDocument();
    $xmldoc->substituteEntities = true;  // collapse ampersands for HTML
    $xml = hideEntities(file_get_contents($xmlfilename));
    $xmldoc->loadXML($xml);
    ...
    $proc->transformToXML($doc);
Add to favourites       Subscribe comments       Copy code       Bookmark
Sign up to add your own comment here!

Shared by:

zweibieren

Mail user Add to friends
All user contributed content is available under the LGPL unless specified otherwise.
Remaining copyrights Regin Gaarsmand © 2006-2008
About SourceRally.net
Adelgazar sin trucos Programador PHP