note 34786 added to function.xml-set-character-data-handler

From: Date: Wed, 06 Aug 2003 17:23:05 +0000
Subject: note 34786 added to function.xml-set-character-data-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-53527@lists.php.net to get a copy of this message
Here are two ways to deal with named entities in the XML. 1. Put a list of named entities at the front so the parser knows what they all mean $decl = '<!DOCTYPE rootname [ <!ENTITY frac12 "&#x00BD;" > <!ENTITY frac14 "&#x00BC;" > <!ENTITY frac34 "&#x00BE;" > <!ENTITY frac18 "&#x215B;" > <!ENTITY frac38 "&#x215C;" > <!ENTITY frac58 "&#x215D;" > <!ENTITY frac78 "&#x215E;" > <!ENTITY frac13 "&#x2153;" > <!ENTITY frac23 "&#x2154;" > <!ENTITY frac15 "&#x2155;" > <!ENTITY frac25 "&#x2156;" > <!ENTITY frac35 "&#x2157;" > <!ENTITY frac45 "&#x2158;" > <!ENTITY frac16 "&#x2159;" > <!ENTITY frac56 "&#x215A;" > <!ENTITY mdash "&#x2014;" > ..... lots of others <!ENTITY uuml "&#252;" > <!ENTITY yacute "&#253;" > <!ENTITY thorn "&#254;" > <!ENTITY yuml "&#255;" > ]>'; $parseThis = $decl . "<rootname> ..... </rootname>"; This works fine for all the single-byte (European) codes, but not the wide codes like emdash or frac18. They seem to be trashed when the character data handler gets them. They all echo as "?" There may be a way to make them work, but until I find it, or a newer release takes care of it, here is a work-around that does work. 2. Rewrite every ampersand as &amp; in the input stream $ampXML = str_replace ("&", "&amp;", $sourceXML); Now the parser will see &amp;foo; instead of &foo; It does not try to decode it, so wide (two byte) values are not a problem, and no list of names is needed. When you write that to your output you have &foo; which is usually fine for the next stage of your process. ---- Manual Page -- http://www.php.net/manual/en/function.xml-set-character-data-handler.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34786 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34786&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34786&report=yes

« previous php.notes (#53527) next »