Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

external DTD file questions

 
Jane Somerfield
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Can I reuse standard entities dedfined in
external DTD files in following way in my XML?
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE author
[
<!ELEMENT root (ANY)>
<!ENTITY %std1 SYSTEM "Standard1.dtd">
<!ENTITY %std2 SYSTEM "Standard2.dtd">
%std1;
%std2;
]>
<root>
......
</root>
Thanks.
Jane
 
Rakesh Gudur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jane,
Do you mean that you don't want to refer to the whole DTD and only want to use the parameter entities declared in the DTD? In this case I don't think it is possible to specifically use "ONLY" selected entities.
You may use the whole DTD, refer to the parameter entities you want and add "IGNORE" clause to avoid the other DTD sections.
I hope this solves the problem.
Rakesh.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jane,
Your code looks just fine besides the missing space in the parameter entity declarations.
It should be -

Cheers,
Dan
 
Jane Somerfield
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you all.
 
Jane Somerfield
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakesh:
I want to know whether I can include more than one
external *.dtd files within one one DOCTYPE.
I guess the answer is yes. Thanks.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since there is no limitation that I know of on the number of parameter entity declarations, you can use this interesting mechanism to include as many external DTDs as you like.
Cheers,
Dan
 
Rakesh Gudur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jane,
You cannot include multiple DTD with a single DOCTYPE. Further, an XML file can have only one DOCTYPE declaration containing DTD declarations.
You may refer to Pg 139 of Prof CML Second Ed.(Wrox) for this clarification.
There is a round-about way of using multiple DTD in a single XML. Include your DTDs in one DTD like a.dtd, b.dtd, c.dtd...in a parent DTD p.dtd as ENTITY declarations. Now refer to p.dtd in your XML file. Refer to Pg 175 of the same book for an example.
Regards,
Rakesh
 
Jane Somerfield
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I read both P139 and P175 of PXML2.
The highlight box on P139 is copied as following:
"An XML document can be associated with one DTD,
using a single DOCTYPE declaration (though this
one DTD may be divided into internal and external
subsets)."
My question is whether the "external subsets" can
be separated dtd files.
Mapraputa: Can you help us on this? Thanks.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jane,
You posted the code that demonstrates that these external subsets can be held in separate dtd files.
What isn't clear?
Dan
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To experiment, I composed simple hierarchical structure
<JavaRanch>
...<forum>
... ... ... <thread>
... ... ... ... ... ... <post/>
and splitted DTD for it in three parts:
Input xml:
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE JavaRanch
[
<!ELEMENT JavaRanch (forum+)>
<!ENTITY % forum SYSTEM "forum.dtd">
<!ENTITY % thread SYSTEM "thread.dtd">
%forum;
%thread;
]>
<JavaRanch>
<forum>
<thread>
<post/>
</thread>
</forum>
</JavaRanch>
Forum.dtd
<!ELEMENT forum (thread+)>
Thread.dtd
<!ELEMENT thread (post+)>
<!ELEMENT post (#PCDATA)>
<!ATTLIST post quality CDATA #FIXED "high">
(later I added default value for an attribute to check if external declarations are, in fact, read).
Merlot detected an error and said that element "forum" refers to undeclared element "thread". IE ate the input without any complain. XML Spy didn't say a word against either (but XML Spy is know for allowing incorrect DTDs). Finally, I run primitive XSLT with Xalan, and not only didn't Xalan complain, it indeed processed declarations from external DTDs because "quality" attribute got its value.
XSLT:
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template >
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<JavaRanch>
<forum>
<thread>
<post quality="high"/>
</thread>
</forum>
</JavaRanch>
So we must admit that it works (Of course, Dan already said it three posts ago )
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a little question on the parameter entity declaration as given below -
sample.dtd --->
<!ENTITY % pcdat "(#PCDATA)">
<!ELEMENT jaya %pcdat;>
<!ENTITY % parEntt1 "<!ELEMENT car %pcdat;>">
sample.xml -->
case (1)
<!DOCTYPE root[
<!ELEMENT root ANY>
<!ATTLIST root attr1 CDATA #REQUIRED>
<!ENTITY localEntity "pcdat">
<!ENTITY % some SYSTEM "sample.dtd">
%some;
%parEntt1;
]>
<root attr1="&localEntity;">
&localEntity;
<car/>
</root>
If i include the sample.dtd as shown above as an external parameter entity, the %parEntt1 (which refers to the car element) gets resolved fine;
=================================================
If i have the xml document's DTD changed as shown below -
case (2)
<!DOCTYPE root SYSTEM "sample.dtd"[
<!ELEMENT root ANY>
<!ATTLIST root attr1 CDATA #REQUIRED>
<!ENTITY localEntity "pcdat">
%parEntt1;
]>
<root attr1="&localEntity;">
&localEntity;
<car/>
</root>
it gives me the following error -
"Parameter entity must be defined before it is used. "
Is it not being able to see the %parEntt1; delcaration eventhough i'm doing the following -
<!DOCTYPE root SYSTEM "sample.dtd"[....
I guess in case (1), all the contents of sample.dtd are being inserted by %some; Isn't something similar should happen even for this case - <!DOCTYPE root SYSTEM "sample.dtd"[....
Can someone explain what is the exact difference
in both of these procedures?
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic