Re: [xml-dev] Transforming documents with undefined entities

From
G. Ken Holman <>
To
Andrew Campbell <>, "" <>
Date
2016-04-19T12:41:56Z
ID
<>
Thread
Re: [xml-dev] Transforming documents with undefined entities
The answer is in the XML Spec section 4.1:

  https://www.w3.org/TR/2008/REC-xml-20081126/#sec-references
  Well-formedness constraint: Entity Declared
  ...
  Note that non-validating processors are not obligated to read
  and process entity declarations occurring in parameter entities
  or in the external subset; for such documents

I note in your example that you don't have a 
standalone declaration, and so the processor is 
allowed to ignore the entity reference:

<!DOCTYPE chapter SYSTEM "external.dtd">
<chapter>&badent;</chapter>

Changing your instance as follows:

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE chapter SYSTEM "external.dtd">
<chapter>&badent;</chapter>

... triggers an error.

I hope this helps.

. . . . . . Ken

At 2016-04-19 08:27 +0000, Andrew Campbell wrote:
>Hi everyone,
>
>I’m experiencing something unexpected when 
>transforming documents with undefined entities 
>using Saxon. I asked on the Saxon mailing list, 
>and Michael Kay suggested I tried asking here too.
>
>I have two XML files, one with an internal DTD 
>(badent-internal.xml), one with an external DTD 
>(badent-external.xml). Both of them reference an 
>undefined entity (&badent;). When I parse either 
>of them with xmllint, the undefined entity is reported.
>
>$ xmllint badent-internal.xml
>badent-internal.xml:4: parser error : Entity 'badent' not defined
><chapter>&badent;</chapter>
>                  ^
>
>When I try to transform them on the command line 
>using Saxon, badent-internal.xml throws an 
>error, but badent-external.xml is transformed as 
>if the entity reference were not present.
>
>$ java -cp 
>~/Documents/XML/SaxonHE9-6-0-7J/saxon9he.jar 
>net.sf.saxon.Transform -xsl:simple.xsl -s:badent-internal.xml
>Error on line 4 column 18 of badent-internal.xml:
>   SXXP0003: Error reported by XML parser: The 
> entity "badent" was referenced, but not declared.
>org.xml.sax.SAXParseException; systemId: 
>file:/Users/acam0006/Desktop/saxon.entity.test/missing.entity/badent-internal.xml; 
>lineNumber: 4; columnNumber: 18; The entity 
>"badent" was referenced, but not declared.
>
>$ java -cp 
>~/Documents/XML/SaxonHE9-6-0-7J/saxon9he.jar 
>net.sf.saxon.Transform -xsl:simple.xsl -s:badent-external.xml
><?xml version="1.0" encoding="UTF-8"?><success/>
>
>I expected both files to throw the same error. What is going on?
>
>I have attached the relevant files to this email.
>
>Andrew


--
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training @US$45: http://goo.gl/Dd9qBK |
Crane Softwrights Ltd. _ _ _ _ _ _ http://www.CraneSoftwrights.com/x/ |
G Ken Holman _ _ _ _ _ _ _ _ _ _ mailto: |
Google+ blog _ _ _ _ _ http://plus.google.com/+GKenHolman-Crane/posts |
Legal business disclaimers: _ _ http://www.CraneSoftwrights.com/legal |


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus