[Expat-discuss] Parsing External Entities

Michael B. Allen miallen at eskimo.com
Wed Jan 15 02:44:10 EST 2003


I have two questions regarding parsing external entities. First I have
an XML file:

  <?xml version="1.0"?>
  <!DOCTYPE staff SYSTEM "err.dtd" [
     <!ENTITY E "This is a general entity">
  ]>
  <err>
  The entity is: &E;
  </err>

and the DTD it references has one useless ELEMENT declaration:

  <!ELEMENT employeeId (#PCDATA)>

Now this may be my ignorace of XML but when I run this through my
dump program which just regurgitates XML the ExternalEntityRefHandler
runs OK and as you can see from the dialog below it completed parsing
the DOCTYPE definition however it is not resolving the internal entity
'E'. If I remove 'SYSTEM "err.dtd"' the entity is resolved properly and
the program completes successfully. Why does this happen?

  <?xml version="1.0"?>
  <?DOCTYPE staff SYSTEM "err.dtd" [
     <!ENTITY E "This is a general entity">
     <!ELEMENT employeeId (#PCDATA)>
  ]><err>
  expatdump.c:270:parse: An XML parser error occured: line 6 col 15 off 40: undefined entity:
  eneral entity"> ]> <err> The entity is: &E; </err>
                                          ^
    expatdump.c:352:expatdump: 
    expatdump.c:380:main: Failure

Also, using the external entity XML_Parser created with
XML_ExternalEntityParserCreate my dump program segfaults if I attempt
to free it with XML_ParserFree. I suppose this parser is simply the same
parser in a different state and therefore I need not free it?

Thanks,
Mike

-- 
A  program should be written to model the concepts of the task it
performs rather than the physical world or a process because this
maximizes  the  potential  for it to be applied to tasks that are
conceptually  similar and, more important, to tasks that have not
yet been conceived. 



More information about the Expat-discuss mailing list