note 34786 added to function.xml-set-character-data-handler
| From: | morris_hirsch at hotmail dot com | 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 "½" >
<!ENTITY frac14 "¼" >
<!ENTITY frac34 "¾" >
<!ENTITY frac18 "⅛" >
<!ENTITY frac38 "⅜" >
<!ENTITY frac58 "⅝" >
<!ENTITY frac78 "⅞" >
<!ENTITY frac13 "⅓" >
<!ENTITY frac23 "⅔" >
<!ENTITY frac15 "⅕" >
<!ENTITY frac25 "⅖" >
<!ENTITY frac35 "⅗" >
<!ENTITY frac45 "⅘" >
<!ENTITY frac16 "⅙" >
<!ENTITY frac56 "⅚" >
<!ENTITY mdash "—" >
..... lots of others
<!ENTITY uuml "ü" >
<!ENTITY yacute "ý" >
<!ENTITY thorn "þ" >
<!ENTITY yuml "ÿ" >
]>';
$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 & in the input stream
$ampXML = str_replace ("&", "&", $sourceXML);
Now the parser will see &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