DTD and parameter entity replacement

  • Thread starter Tuomas Rannikko
  • Start date
T

Tuomas Rannikko

Hello!

I have a simple question about DTDs: Should this be possible?

<!DOCTYPE root [

<!ELEMENT root (#PCDATA)>

<!ELEMENT this EMPTY>
<!ELEMENT that EMPTY>
<!ENTITY % param "that">


In the XML specification I can't find the spot where it says this would
be disallowed; however Xerces complains about the parameter entity being
in markup.

- Tuomas
 
J

Joe Kesselman

In the XML specification I can't find the spot where it says this
would >be disallowed

In section 2.8, down a little ways:

"Well-Formedness Constraint: PEs in Internal Subset
In the internal DTD subset, parameter-entity references can occur only
where markup declarations can occur, not within markup declarations.
(This does not apply to references that occur in external parameter
entities or to the external subset.)"

Tim Bray's _Annotated_XML_Specification_
(http://www.xml.com/axml/testaxml.htm) has a comment on why this rule
was put in place. (That site is an excellent resource for understanding
why XML 1.0 is as it is. Unfortunately, Tim has said he probably won't
have time to bring it up to date for XML 1.1, never mind namespaces and
so on. There's an opportunity here for someone to contribute to the
community.)

For what it's worth, Appendix D shows a hideous workaround, which
involves constructing the whole entity definition in a single parameter
entity and using that. To find it, search for "error-prone" -- which it
is, and I strongly recommend that you find another solution.
 
P

Peter Flynn

Tuomas said:
Hello!

I have a simple question about DTDs: Should this be possible?

Yes, but not in an Internal Subset.
<!DOCTYPE root [

<!ELEMENT root (#PCDATA)>

This should probably be "test", not "#PCDATA".
<!ELEMENT this EMPTY>
<!ELEMENT that EMPTY>
<!ENTITY % param "that">



In the XML specification I can't find the spot where it says this would
be disallowed; however Xerces complains about the parameter entity being
in markup.

Joe has pointed out where. Just snip out the declarations and put them
in test.dtd (with the content model for "root" being "test"), then

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE root SYSTEM "test.dtd">
<root>
<test>
<this/>
<that/>
</test>
</root>

is a valid instance.

///Peter
 
T

Tuomas Rannikko

Joe said:
would >be disallowed

In section 2.8, down a little ways:

"Well-Formedness Constraint: PEs in Internal Subset
In the internal DTD subset, parameter-entity references can occur only
where markup declarations can occur, not within markup declarations.
(This does not apply to references that occur in external parameter
entities or to the external subset.)"

Tim Bray's _Annotated_XML_Specification_
(http://www.xml.com/axml/testaxml.htm) has a comment on why this rule
was put in place. (That site is an excellent resource for understanding
why XML 1.0 is as it is. Unfortunately, Tim has said he probably won't
have time to bring it up to date for XML 1.1, never mind namespaces and
so on. There's an opportunity here for someone to contribute to the
community.)

Ah, yes. I seem to have mixed up my concepts. I had trouble seeing as to
why that would not be allowed, but the annotated specification helps to
clarify that it's allowed ONLY in external subsets (and why).

I guess I'll have to keep track whether I'm parsing an external or
internal subset. (I'm writing a parser just for the fun of it ;) )

Thanks,
- Tuomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,002
Messages
2,570,260
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top