You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Dick Deneer <d....@chello.nl> on 2010/01/16 22:29:25 UTC

How to check for entity reference in attribute

When I parse xml with an entity refererence in an attribute to a DOM  
tree, I am not able to serialize the xml back to the original content.
The question of retaining this references has been asked before in  
this forum and I am aware that this is not supported by xerces.
But it is possble to check by myself for the existence of such  
entities? In other words :  When I use a contenthandler, how could I  
check for  entities that are declared within attributes?

Example xml where the salary attribute has the entity &one which I  
want to detect in the parsing.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel SYSTEM "personal.dtd" [
  <!ENTITY name "Big">
  <!ENTITY one "1">
]>
<person id="Big.Boss" salary="&one;">
    <name><family>Boss</family> <given>&name;</given></name>
     <email>chief@foo.com</email>
   </person>
</personnel>


Regards,
Dick Deneer

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: How to check for entity reference in attribute

Posted by Dick Deneer <di...@donkeydevelopment.com>.
Michael,

Thanks for your quick response.
I will use a simple internal parser to detect them. If the xml is  
wellformed this should not be too complex

Thanks,
Dick Deneer


Op 16 jan 2010, om 23:21 heeft Michael Glavassevich het volgende  
geschreven:

> Even if Xerces internally tracked entity boundaries within attribute  
> values there would be no way to report this information to you  
> through SAX [1]. Only the normalized value [2] of an attribute is  
> exposed. In other words, the entity references will have been  
> replaced before your ContentHandler receives the attribute values.
>
> [1] http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/ext/LexicalHandler.html#startEntity(java.lang.String)
> [2] http://www.w3.org/TR/REC-xml/#AVNormalize
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Dick Deneer <d....@chello.nl> wrote on 01/16/2010 04:29:25 PM:
>
> > When I parse xml with an entity refererence in an attribute to a DOM
> > tree, I am not able to serialize the xml back to the original  
> content.
> > The question of retaining this references has been asked before in
> > this forum and I am aware that this is not supported by xerces.
> > But it is possble to check by myself for the existence of such
> > entities? In other words :  When I use a contenthandler, how could I
> > check for  entities that are declared within attributes?
> >
> > Example xml where the salary attribute has the entity &one which I
> > want to detect in the parsing.
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE personnel SYSTEM "personal.dtd" [
> >   <!ENTITY name "Big">
> >   <!ENTITY one "1">
> > ]>
> > <person id="Big.Boss" salary="&one;">
> >     <name><family>Boss</family> <given>&name;</given></name>
> >      <email>chief@foo.com</email>
> >    </person>
> > </personnel>
> >
> >
> > Regards,
> > Dick Deneer
> >
> >  
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-users-help@xerces.apache.org
>


Re: How to check for entity reference in attribute

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Even if Xerces internally tracked entity boundaries within attribute values
there would be no way to report this information to you through SAX [1].
Only the normalized value [2] of an attribute is exposed. In other words,
the entity references will have been replaced before your ContentHandler
receives the attribute values.

[1]
http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/ext/LexicalHandler.html#startEntity
(java.lang.String)
[2] http://www.w3.org/TR/REC-xml/#AVNormalize

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Dick Deneer <d....@chello.nl> wrote on 01/16/2010 04:29:25 PM:

> When I parse xml with an entity refererence in an attribute to a DOM
> tree, I am not able to serialize the xml back to the original content.
> The question of retaining this references has been asked before in
> this forum and I am aware that this is not supported by xerces.
> But it is possble to check by myself for the existence of such
> entities? In other words :  When I use a contenthandler, how could I
> check for  entities that are declared within attributes?
>
> Example xml where the salary attribute has the entity &one which I
> want to detect in the parsing.
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE personnel SYSTEM "personal.dtd" [
>   <!ENTITY name "Big">
>   <!ENTITY one "1">
> ]>
> <person id="Big.Boss" salary="&one;">
>     <name><family>Boss</family> <given>&name;</given></name>
>      <email>chief@foo.com</email>
>    </person>
> </personnel>
>
>
> Regards,
> Dick Deneer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org