„Dokumentumtípus-definíció” változatai közötti eltérés

[nem ellenőrzött változat][nem ellenőrzött változat]
Tartalom törölve Tartalom hozzáadva
Tiplity (vitalap | szerkesztései)
Tiplity (vitalap | szerkesztései)
319. sor:
 
If the XML document type declaration includes any SYSTEM identifier for the external subset, it can't be safely processed as standalone: the URI should be retrieved, otherwise there may be unknown named character entities whose definition may be needed to correctly parse the effective XML syntax in the internal subset or in the document body (the XML syntax parsing is normally performed ''after'' the substitution of all named entities, excluding the five entities that are predefined in XML and that are implicitly substituted ''after'' parsing the XML document into lexical tokens). If it just includes any PUBLIC identifier, it ''may'' be processed as standalone, if the XML processor knows this PUBLIC identifier in its local catalog from where it can retrieve an associated DTD entity.
 
== XML DTD schema example ==
An example of a very simple external XML DTD to describe the schema of a list of persons might consist of:
 
<source lang="xml">
<!ELEMENT people_list (person)*>
<!ELEMENT person (name, birthdate?, gender?, socialsecuritynumber?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT birthdate (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT socialsecuritynumber (#PCDATA)>
</source>
 
Taking this line by line:
 
# <code>people_list</code> is a valid element name, and an instance of such an element contains any number of <code>person</code> elements. The <code>*</code> denotes there can be 0 or more <code>person</code> elements within the <code>people_list</code> element.
# <code>person</code> is a valid element name, and an instance of such an element contains one element named <code>name</code>, followed by one named <code>birthdate</code> (optional), then <code>gender</code> (also optional) and <code>socialsecuritynumber</code> (also optional). The <code>?</code> indicates that an element is optional. The reference to the <code>name</code> element name has no <code>?</code>, so a <code>person</code> element ''must'' contain a <code>name</code> element.
# <code>name</code> is a valid element name, and an instance of such an element contains "parsed character data" (#PCDATA).
# <code>birthdate</code> is a valid element name, and an instance of such an element contains parsed character data.
# <code>gender</code> is a valid element name, and an instance of such an element contains parsed character data.
# <code>socialsecuritynumber</code> is a valid element name, and an instance of such an element contains parsed character data.
 
An example of an XML file which makes use of and conforms to this DTD follows. The DTD is referenced here as an external subset, via the SYSTEM specifier and a URI. It assumes that we can identify the DTD with the relative URI reference "example.dtd"; the "people_list" after "!DOCTYPE" tells us that the root tags, or the first element defined in the DTD, is called "people_list":
 
<source lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE people_list SYSTEM "example.dtd">
<people_list>
<person>
<name>Fred Bloggs</name>
<birthdate>2008-11-27</birthdate>
<gender>Male</gender>
</person>
</people_list>
</source>
 
One can render this in an XML-enabled [[web browser|browser]] (such as [[Internet Explorer]] or [[Mozilla Firefox]]) by pasting and saving the DTD component above to a text file named ''example.dtd'' and the XML file to a differently-named text file, and opening the XML file with the browser. The files should both be saved in the same directory. However, many browsers do not check that an XML document conforms to the rules in the DTD; they are only required to check that the DTD is syntactically correct. For security reasons, they may also choose not to read the external DTD.
 
The same DTD can also be embedded directly in the XML document itself as an internal subset, by encasing it within [square brackets] in the document type declaration, in which case the document no longer depends on external entities and can be processed in standalone mode:
 
<source lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE people_list [
<!ELEMENT people_list (person)*>
<!ELEMENT person (name, birthdate?, gender?, socialsecuritynumber?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT birthdate (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT socialsecuritynumber (#PCDATA)>
]>
<people_list>
<person>
<name>Fred Bloggs</name>
<birthdate>2008-11-27</birthdate>
<gender>Male</gender>
</person>
</people_list>
</source>
 
Alternatives to DTDs (for specifying schemas) are available:
* [[XML Schema (W3C)|XML Schema]], also referred to as XML Schema Definition (XSD), has achieved Recommendation status within the W3C,<ref>{{cite web |url=http://www.w3.org/TR/xmlschema-1/ |title=XML Schema Part 1: Structures Second Edition |author=W3C |publisher=W3C |accessdate=2011-05-17}}</ref> and is popular for "data oriented" (that is, transactional non-publishing) XML use because of its stronger typing and easier round-tripping to Java declarations{{Citation needed|date=February 2011}}. Most of the publishing world has found that the added complexity of XSD would not bring them any particular benefits{{Citation needed|date=November 2008}}, so DTDs are still far more popular there. An XML Schema Definition is itself an XML document while a DTD is not.
* [[RELAX NG]], which is also a part of [[DSDL]], is an ISO international standard.<ref>{{cite web |url=http://www.iso.org/iso/iso_catalogue/catalogue_ics/catalogue_detail_ics.htm?csnumber=37605 |title=ISO/IEC 19757-2:2003 - Information technology -- Document Schema Definition Language (DSDL) -- Part 2: Regular-grammar-based validation -- RELAX NG |author=ISO |publisher=ISO |accessdate=2011-05-17}}</ref> It is more expressive than XSD{{Citation needed|date=February 2011}}, while providing a simpler syntax{{Citation needed|date=February 2011}}, but commercial software support has been slow in coming.
 
== See also ==