Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internal DTD & External DTD

 
Siva shanmugam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me,
Is it is possible to redefine the elements in Internal DTD subset which are already defined in external DTD subset ?
External DTD file ex1.dtd is like this
----------------------------------
<!ELEMENT eleName (#PCDATA)>

Xml file is like this
---------------------
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!DOCTYPE eleName SYSTEM "ex1.dtd"
[
<!ELEMENT eleName (childElement1|childElement2)*>
] >
<eleName/>
This above code works fine in IE 6.0
but it gives, Element type "eleName" must not be declared more than once
Error in Xerces Parser.
 
Dean Jones
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmmm u cant declare a element already defined in the external DTD in the internal DTD.The MSXML parser with the IE is not fuly compliant with the standards bu Xalan wil not leave u ,that is the Resaon dear
 
Samir Shah
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML paresers implementations vary for this.
According to W3 Specs.
1) No ELEMENT can be declared twice.
2) ATTRIBUTE can be declared more than once BUT only first ATTRIBUTE declaration is binding. If two ATTLIST is defined for an ELEMENT, attribute definations will be merged (i.e. new attributes defined in subsequent ATTLIST will be added to ATTLIST)
3) ENTITY can be declared more than once BUT only First ENTITY declaration is binding.
4) Only one notation declaration can declare a given Name
 
jim yin
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Samir Shah:
1) No ELEMENT can be declared twice.

I still have a doubt for this. In PXML2 (p138), it says:

...the external subset description of an element might allow several child elements, while the internal subset version specifies an empty element. Any XML data containing this DTD combination had better use an empty element, or it would be considered invalid.

Does that mean it does not allow to declare an element twice in the same subset, but allow to declare it twice in an internal and an external subsets since the internal one can override the external one? Any thoughts?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samir is absolutely right about the four points he made.
It seems to me that the only construct in the DTD that can be redefined is the parameter entity.
Cheers,
Dan
 
Vasudha Deepak
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes an Element can only be defined once,considering both the internal and the external DTD.
In the following example the element1 has been defined both in the external and internal DTD.However a DTD/Schema error appears in XML Spy stating the the element1 has been defined already.
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root SYSTEM "test.dtd" [
<!ELEMENT root (element1)>
<!ELEMENT element1 (#PCDATA)>
]>
<root>
<element1/>
</root>

test.dtd
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT element1 (#PCDATA)>

Vasudha
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samir said -
3) ENTITY can be declared more than once BUT only First ENTITY declaration is binding.

Please note that the internal DTD subset is read _first_. This allows us to redefine an entity, which was originally defined in the external subset, in the internal subset.
Cheers,
Dan
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same applies for attributes as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic