468,103 Members | 1,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

How to get XML parser to recognize entities (eg. —)

I'm using PHP's XML parser to validate user-entered XHTML fragments (I
wrap them in a top-level element and send them through the parser). It
works a treat, except for handling entities:

— -- is fine, but
— -- throws an error, e.g:

"XML error: undefined entity at line 11, char 415"

(Making an entity handler didn't help, at it fails at the parsing stage.)

Obviously I could search and replace to turn entities into their
character values, but that's pretty ugly. How can I get the XML parser
to recognize XHTML's entity set? Do I need to wrap the text fragment in
a full-blown XHTML document, including the DTD specifier?

Thanks in advance,
Kalessin.

Jul 17 '05 #1
2 9069
On Wed, 17 Dec 2003 11:16:43 GMT, Kalessin
<try@http://jesus.com.au/html/email/kalessin> wrote:
I'm using PHP's XML parser to validate user-entered XHTML fragments (I
wrap them in a top-level element and send them through the parser). It
works a treat, except for handling entities:

— -- is fine, but
&mdash; -- throws an error, e.g:

"XML error: undefined entity at line 11, char 415"

(Making an entity handler didn't help, at it fails at the parsing stage.)

Obviously I could search and replace to turn entities into their
character values, but that's pretty ugly. How can I get the XML parser
to recognize XHTML's entity set? Do I need to wrap the text fragment in
a full-blown XHTML document, including the DTD specifier?


Possibly. If you look at the XML spec, there's only a limited set of entities
that XML parsers must accept without them being declared in a DTD:

http://www.w3.org/TR/REC-xml#sec-predefined-ent

The XHTML DTD imports the character references near the start:

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

Could you make a mini-DTD that only imports the entities?

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2
> The XHTML DTD imports the character references near the start:

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

Could you make a mini-DTD that only imports the entities?


The real links for entities are:
http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent
http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Himanshu Garg | last post: by
1 post views Thread by Bob | last post: by
11 posts views Thread by Tjerk Wolterink | last post: by
6 posts views Thread by Jan Danielsson | last post: by
4 posts views Thread by Paul Rubin | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.