René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Document type definition (DTD) | ||
External DTDSYSTEM<!DOCTYPE root-element SYSTEM "http://xyz.qq/abc/def.dtd">
SYSTEM means that a validating parser needs the dtd when it validates an XML document.
PUBLIC<!DOCTYPE root-element PUBLIC "path/abc/def.dtd">
PUBLIC means that a validating parser might use a 'cached' ???? version of the DTD.
Mixing<!DOCTYPE root-element PUBLIC "path/abc/def.dtd" "http://xyz.qq/abc/def.dtd">
This form uses http://xyz.qq.abc.def.dtd only if path/abc/def.dtd is not available.
The structure of a DTD<!ENTITY><!ENTITY foo "bar">
foo is used like
&foo; <?xml version="1.0"?> <!DOCTYPE bar [ <!ENTITY foo "HERE COMES THE REPLACED STRING"> <!ELEMENT bar ANY> ]> <bar>&foo; </bar>
External entity:
<?xml version="1.0"?> <!DOCTYPE bar [ <!ENTITY foo SYSTEM "c:\x.txt"> <!ELEMENT bar ANY> ]> <bar>&foo; </bar>
&foo; will now be replaced with the contents of x.txt
Parameter entities: Parameter entities are identifiable by their percent sign instead of the ampersand (&).
<!ENTITY % warning "severe | error | fatal">
Parameter entities have DTD text, not XML text. It cannot appear within an XML document.
Parameter entity references may not be used within markup in an internal DTD
<?xml version="1.0" ?> <!DOCTYPE r SYSTEM "file://c:/path/to/parameter_entity.dtd" [ <!ENTITY % warning "error | severe | fatal"> ]> <r> <severe>x</severe> <error> y</error> <fatal> z</fatal> </r> parameter_entity.dtd
<!ELEMENT r ((%warning;)*)> <!ELEMENT severe (#PCDATA)> <!ELEMENT error (#PCDATA)> <!ELEMENT fatal (#PCDATA)>
As parser read the internal subset first %warning; is already defined when reading the dtd in the external subset.
Unparsed entities
An unparsed entity looks similar to an external entity with the NDATA keyword followed by
notation identifier.
<!ENTITY foo SYSTEM "something.txt" NDATA txt>
NDATA (Notation Data) means that this ENTITY'S content is assigned to a certain notation type.
Unparsed entities can occur only in Attribute values that are declared to be of types
ENTITY or ENTITIES.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE document [ <!ELEMENT document (sound)+> <!ELEMENT sound EMPTY> <!ATTLIST sound what ENTITY #REQUIRED > <!NOTATION WAV SYSTEM "/usr/local/bin/wave_player"> <!ENTITY music SYSTEM "drop.wav" NDATA WAV> <!ENTITY wwwc "World Wide Web Corporation"> ]> <document> <sound what="music"/> </document> <!ELEMENT>
<!ATTLIST>
Attributes indicate properties of Elements.
<?xml version="1.0" ?> <!DOCTYPE r [ <!ELEMENT r (a*) > <!ELEMENT a (#PCDATA)> <!ATTLIST a a_1 CDATA #REQUIRED > <!ATTLIST a a_2 CDATA #IMPLIED > <!ATTLIST a a_3 CDATA "def" > <!ATTLIST a a_4 CDATA #FIXED "def" > <!ATTLIST a a_5 (enum_1|enum_2|enum_3) #REQUIRED > <!ATTLIST a a_6 (enum_1|enum_2|enum_3) #IMPLIED > <!ATTLIST a a_7 (enum_4|enum_5|enum_6) "enum_5" > ]> <r> <a a_5="enum_1" a_1="Y" /> </r>
Types of attributes:
Attribute values are subject to attribute-value normalization.
See also nesting entities.
<!NOTATION>
Declares a notation type. A notation type is an instruction that defines how to process (possibly binary) data.
<!NOTATION jpg SYSTEM "jpgviewer.exe"> <!NOTATION gif SYSTEM "gif.exe">
Here, jpg and gif, respectively, would be the notation types.
<![CDATA[ ]]>Disadvantages of DTDs
XML Schema tries to address some of these disadvantages.
|