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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kalessin

    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.

  • Andy Hassall

    #2
    Re: How to get XML parser to recognize entities (eg. —)

    On Wed, 17 Dec 2003 11:16:43 GMT, Kalessin
    <try@http://jesus.com.au/html/email/kalessin> wrote:
    [color=blue]
    >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?[/color]

    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:



    The XHTML DTD imports the character references near the start:



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

    --
    Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
    Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

    Comment

    • Alessandro Bondi

      #3
      Re: How to get XML parser to recognize entities (eg. &amp;mdash;)

      > The XHTML DTD imports the character references near the start:[color=blue]
      >
      > http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
      >
      > Could you make a mini-DTD that only imports the entities?[/color]

      The real links for entities are:





      Comment

      Working...