Parsing an XML... <!entity references to .xml"> break simplexml

So I have an XML that contains a bunch of tables that I’m turning into an HTML.

Problem is, I have no idea how to deal with this:

[code]<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<!DOCTYPE cstgschema SYSTEM "a.dtd" [ ]>
&a;
more stuff
</xml>
[/code]

Whenever I simplexml load the file, I get errors for all the &a references. Namely errors like this: 
[code]Warning: simplexml_load_file() [function.simplexml-load-file]: &a; in C:\location\file.php on line 8[/code]

Line 8 of course being 
[php]$xml = simplexml_load_file('../a/b.xml');[/php]

with b.xml being the file with the code at the top in it. 

How do I deal with these entity references? I am new to PHP so I don't really know where to start. It seems that I might need to use a different parser like DOM... Is this the case? If so, how do I deal with these entity references in DOM?

I forgot to mention, it also gives me this error for the entity itself:

Warning: simplexml_load_file() [function.simplexml-load-file]: ../a/a.xml:385: parser error : Entity 'a' not defined in C:\location\file.php on line 8

ugh… after spending a million hours trying to figure out DOMDocument node traversing, etc… I found out a simple and stupid fix for it.

I added the following above
[php]$options = LIBXML_DTDLOAD | LIBXML_NOENT | LIBXML_DTDVALID | LIBXML_NOCDATA;
$xml2 = new DOMDocument();
$xml2->load(’…/a/a.xml’, $options);[/php]

and I changed the simple_xml_loadfile to

[php]$xml = simplexml_import_dom($xml2);[/php]

and that fixed ALL the problems. It now properly calls the documents referenced in "<!entity &b “b.xml>” and places them in the appropriate places where “&b” shows up.

Hope this helps someone if they run across this problem in the future.

Sponsor our Newsletter | Privacy Policy | Terms of Service