----- Original Message -----
From: KAVANAGH, Michael <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 15, 2001 12:28 PM
Subject: XML::Parser -- Problem with undefined entities in element
attributes


> Hi there,
> I've been bumping my head up against this problem all morning now, and
can't
> come up with an answer, maybe someone with XML::Parser experience can
help.
> The XML::Parser documentation doesn't really have any suggestions.
>
> Normally you can use the NoExpand method to prevent the parser from
> expanding entity references in the text.
> But this doesn't affect entity references that appear in attribute values.
>
> Is there any way to handle entity references in attribute values?

Actually more then one way. Depends if  you want to preserve the entities or
translate them...

> My problem is I have tags in my xml that contain entity references like
> this:
> <section name="text &reg;"></section>
>
> and XML::Parser generates the following error:
> undefined entity at line 6, column 33, byte 218:
>
> <section name="text &reg;"></section>
> ===============^

All non-standard entities (and there are quit some) should be in the DOCTYPE
declaration at the top of the document.
SO there should be something there like:
<!DOCTYPE doc [
<entity reg  &#174; >]

>
> So obviously &reg isn't in the internal set of references, and it is
> generating an error.
> I'd like to set up a handler for this condition, rather than having the
> program die!

If you want to preserve the entities you could translate them to some other
string and then put them back in a starttag handler.
You have to construcy the start tag there (modifying the %attrs hash wont
change the attributes in the original element).

> I have tried setting the ExternEnt handler to handle this case, but it
> doesn't seem to get triggered in this instance.
Nope ExternEnt is fired when the parser sees an external entity reference
(or was it a declaration)...





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to