external DTD with % as default attribute value

S

Sjoerd Mullender

I am trying to create a DTD where some attributes are to have a default
value of "100%". The DTD is modularized similarly to the XHTML DTD
modularization, so that means I have parsed entities that reference
other parsed entities in external subsets.

The problem I'm facing is that the validating parser that I wrote myself
accepts my DTD, but libxml2, Xerces and PyXML don't, and I don't know
how I can fix the DTD so that all parsers are happy, or indeed whether
there is a bug in either my own parser or in the others.

Does anybody have any ideas?

Here is a small example:

File x.xml:
<?xml version="1.0"?>
<!DOCTYPE test PUBLIC "xyzzy" "x.dtd">
<test/>

File x.dtd:
<!ENTITY % test.x.module PUBLIC "plugh" "x.mod">
%test.x.module;

File x.mod:
<!ENTITY % test.test.qname "test">
<!ENTITY % level1 "
attr CDATA '100%'
">
<!ENTITY % level2 "
%level1;
">
<!ENTITY % test.test.content "EMPTY">
<!ELEMENT %test.test.qname; %test.test.content;>
<!ATTLIST %test.test.qname; %level2;>

I can change the value to '&#37;', but then I still get into
trouble. My DTD has more levels of indirection than this example: there
is effectively also an entity

<!ENTITY % level3 "
%level2;
">

and the ATTLIST refers to this level3 entity. The parsers complain
again about the DTD. If I then change the value to &#38;#37; two of
the three accept the document, but the third parser (PyXML) still complains.

Note that & is "&" and % is "%".

--
Sjoerd Mullender


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iQCVAwUBR7IDUz7g04AjvIQpAQIEFQP/Wj+W2dk9PTEqCuo8eZpM+wRcThNpssz7
mb8h9rRvmUQxB4rJx9SlcAKUXdBXjrDeC+FOb+zk6kB1OzShNeqpd4lVtNsOHR+G
0yTR7iEvx+sRBMr9MAUawGTEfT02yxuxoK0iPP1Tyn/V/y0QOethvcy+F+4lMZ45
t8PwTF4bfIg=
=m8Fe
-----END PGP SIGNATURE-----
 
R

Richard Tobin

Sjoerd Mullender said:
I am trying to create a DTD where some attributes are to have a default
value of "100%".

Annoying, isn't it.
If I then change the value to &#38;#37; two of
the three accept the document, but the third parser (PyXML) still complains.

I think that's a bug in PyXML.

I suggest you define a (general internal) entity:

<!ENTITY pct "%">

and then use:

<!ENTITY % level1 "
attr CDATA '100&pct;'
">

The general entity reference won't get expanded until the string
is interpreted as an attribute value, so it shouldn't matter how
much indirection you have.

-- Richard
 
S

Sjoerd Mullender

Annoying, isn't it.

Frustrating is the word.
I think that's a bug in PyXML.

Ok. But apart from the posible bug in PyXML, this would then be the
correct way? Every parsed entity indirection should add an extra &?
I suggest you define a (general internal) entity:

<!ENTITY pct "%">

and then use:

<!ENTITY % level1 "
attr CDATA '100&pct;'
">

The general entity reference won't get expanded until the string
is interpreted as an attribute value, so it shouldn't matter how
much indirection you have.

The problem with this solution is that it changes the accepted language.
Now document writers can use this entity in their documents. But the
language that I'm writing the DTD for does not allow for that.

--
Sjoerd Mullender


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iQCVAwUBR7Km4D7g04AjvIQpAQJVuwQAoexhUk3L7f5qS19fxZdQKBSVRTc5Lf8z
TEYJ5G5aPNphRvP+25yOTu0tkQ6tow9z6rzyQxLepwbVTVuAXnNPhbI29fbtrtnK
wCb75my5j16/CoddZcPMvR8eszkExwCSX1Bn0nap0F1t92mHIYI/y8MFJl+JpDAk
iNCnYIYv6f8=
=sT5N
-----END PGP SIGNATURE-----
 

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
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top