XML external entities

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
julius_h
Forum Newbie
Posts: 1
Joined: Fri Nov 08, 2002 7:56 am

XML external entities

Post by julius_h »

im tying to parse an xml-file via php.
i have a list of entities in an external file ( <!ENTITY ....> )
the IE 5.something displays the xml correctly.
my script (like in the php-manual) does not.
i need to get an output of cdata mixed with entities (from xml).

the thing i dont understand:
why does the xml-parser passes entities (&xxx;) to the default-handler?

im a little bit confused, so is my question, i know.
should'nt the parser translate the entities like they are defined in xml?
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post by PaTTeR »

Huh, may be someone have answer why.
I worked with XML files with German special chrasters (umlauts) and XML data comes with entities. PHP(Expat) parser always stop parse this data when find & in XML data.

With this:

Code: Select all

$xml_data = implode ('',@file($file));

  $xml_data = preg_replace ('/&#252;/', chr(252), $xml_data);
  $xml_data = preg_replace ('/&#246;/', chr(246), $xml_data);
  $xml_data = preg_replace ('/&#228;/', chr(228), $xml_data);
  $xml_data = preg_replace ('/&#235;/', chr(235), $xml_data);
  $xml_data = preg_replace ('/&#220;/', chr(220), $xml_data);
  $xml_data = preg_replace ('/&#214;/', chr(214), $xml_data);
I solved problem. May be this is wrong, may be this is hard way, but this works for me.
Post Reply