[XML-SIG] Disabling entity expansion

Bill Eldridge bill@rfa.org
Thu, 12 Dec 2002 19:04:22 -0500


I have an element v_function referencing external
entities &vf1; &vf2; and &vf3;

<!ELEMENT v_function (#PCDATA)>
                        <!ENTITY vf1 "Animal">
                        <!ENTITY vf2 "Vegetable">
                        <!ENTITY vf3 "Mineral">

Sometimes I'd like to expand these entities
as normal, but other times I'd like to select
<v_function>&vf1;</v_function>
and get &vf1;  or vf3 returned or
even <!ENTITY vf1 "Animal"> ???


Is there a simple way to disable the entity expansion?

from xml.dom.ext.reader.Sax2 import FromXmlStream, FromXmlFile, Reader
from xml.sax import xmlreader, make_parser
from xml.sax.handler import feature_external_ges, feature_external_pes

p = make_parser()
#p.setFeature(feature_external_ges, 0)
#p.setFeature(feature_external_pes, 0)
#doc = FromXmlFile("test.xml", parser=p, validate=0)
doc = FromXmlFile("test.xml", parser=p)

for library in doc.getElementsByTagName("v_function"):
  library.normalize()
  if library.firstChild:
      print library.firstChild.data