„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)
→‎Példák: Első fordítás
Tiplity (vitalap | szerkesztései)
→‎A DTD-k szerkezete: első fordítás
87. sor:
</source>
 
== MarkupA declarationsDTD-k szerkezete ==
 
Egy DTD a hozzá tartozó dokumentum szerkezetének formális szabályait írja le. Felsorolja a dokumentumban használható elemeket, attribútumokat és egyedeket, továbbá azt is megmutatja, hogy miként használhatjuk őket egymással összefüggésben.<ref>{{cite book |last=Bates |first=Chris |title= XML - Elmélet és gyakorlat|year=2004 |publisher=Panem |id= ISBN 963 545 393 0}}</ref>
DTDs describe the structure of a class of documents via element and attribute-list declarations. Element declarations name the allowable set of elements within the document, and specify whether and how declared elements and runs of character data may be contained within each element. Attribute-list declarations name the allowable set of attributes for each declared element, including the [[data type|type]] of each attribute value, if not an explicit set of valid value(s).
 
=== Elemek (ELEMENT) ===
DTD markup declarations declare which [[#Element type declarations|element type]]s, [[#Attribute list declarations|attribute list]]s, [[#Entity declarations|entities]] and [[#Notation declarations|notation]]s are allowed in the structure of the corresponding class of XML documents.<ref>[http://books.google.com/books?id=_NqW2BjQtFIC&lpg=PP1&pg=PP1#v=onepage&q&f=false Sams teach yourself XML in 10 minutes] Von Andrew H. Watt</ref>
 
Az elem típusú deklaráció egy elemet és annak lehetséges tartalmát definiálja. Az érvényes XML-dokumentumok csak a DTD-ben definiált elemeket tartalmazhatják.
=== Element type declarations ===
 
An element type declaration defines an element and its possible content. A valid XML document contains only elements that are defined in the DTD.
 
Various keywords and characters specify an element’s content:
 
* <tt>EMPTY</tt> for specifying that the defined element allows no content, i.e., it can't have any children elements, not even text elements (if there are whitespaces, they are ignored);
* <tt>ANY</tt> for specifying that the defined element allows any content, without restriction, i.e., that it may have any number (including none) and type of children elements (including text elements);
* or an expression, specifying the only elements allowed as direct children in the content of the defined element; this content can be either:
** a '''mixed content''', which means that the content may include at least one text element and zero or more named elements, but their order and number of occurrences can't be restricted; this can be:
*** <tt>( #PCDATA )</tt>: historically meaning ''parsed character data'', this means that only one text element is allowed in the content (no quantifier is allowed);
*** <tt>( #PCDATA | ''element name'' | ... )*</tt>: a limited choice (in an exclusive list between parentheses and separated by "<tt>|</tt>" pipe characters and terminated by the required "<tt>*</tt>" quantifier) of two or more child elements (including only text elements or the specified named elements) may be used in any order and number of occurrences in the content.
** an '''element content''', which means that there must be no text elements in the children elements of the content (all whitespaces encoded between child elements are then ignored, just like comments). Such element content is specified as ''content particle'' in a variant of [[Backus-Naur Form]] without terminal symbols and element names as non-terminal symbols. Element content consists of:
*** a '''content particle''' can be either the name of an element declared in the DTD, or a ''sequence list'' or ''choice list''. It may be followed by an optional ''quantifier''.
**** a '''sequence list''' means an ordered list (specified between parentheses and separated by a "<tt>,</tt>" comma character) of one or more ''content particles'': all the ''content particles'' must appear successively as direct children in the content of the defined element, at the specified position and relative order;
**** a '''choice list''' means a mutually exclusive list (specified between parentheses and separated by a "<tt>|</tt>" pipe character) of two or more ''content particles'': only one of these ''content particles'' may appear in the content of the defined element at the same position.
*** A '''quantifier''' is a single character that immediately follows the specified item to which it applies, to restrict the number of successive occurrences of these items at the specified position in the content of the element; it may be either:
**** <tt>+</tt> for specifying that there must be one or more occurrences of the item — the effective content of each occurrence may be different;
**** <tt>*</tt> for specifying that any number (zero or more) of occurrences in allowed — the item is optional and the effective content of each occurrence may be different;
**** <tt>?</tt> for specifying that there must not be more than one occurrence — the item is optional;
**** If there is no quantifier, the specified item must occur exactly one time at the specified position in the content of the element.
 
For example:
<source lang="xml">
<!ELEMENT cim (sor1, sor2?, sor3*, varos, (megye|allam)?, orszag?, iranyitoszam?)>
<!ELEMENT html (head, body)>
<!ELEMENT psor1 (#PCDATA | p | ul | dl | table | h1|h2|h3)*>
<!ELEMENT sor2 (#PCDATA|hazszam|utcanev)*>
</source>
 
Az előforduló fontosabb struktúrák és kulcsszavak a következők:
Note that element type declarations are ignored by ''non-validating'' SGML and XML parsers (in which cases any elements will be accepted in any order and any number of occurrences in the parsed document), but these declarations are still checked for well-formedness and validity.
 
* '''szekvencia''': zárójeleken belül elemnevek rendezetlen listája vesszőkkel elválasztva.
* '''szelekció''': zcsővonallal (<tt>|</tt>) elválasztott elemnevek között logikai kizáró vagy kapcsolat áll fenn.
* szöveges tartalom: az előzőektől eltérően az elem nem csak újabb elemeket, hanem konkrét adatokat tartalmaz.
** '''feldolgozott karakteres adatok''' (parsed character data): karakterekből álló adatok, melyeket a feldolgozóprogram fel is dolgoz, ezért a kitüntetett karaktereket helyettesíteni kell a nekik megfelelő karakteregyedekkel. Jelölés: <tt>(#PCDATA)</tt>
** '''vegyes tartalom''': az elem vagy karakteres adatokat, vagy elemet tartalmaz. A tartalmi rész első eleme a <tt>#PCDATA</tt> kulcsszó, maga a tartalom pedig kötelező választási lehetőségek listája csővonalakkal elválasztva. A lista végén lévő <tt>*</tt> karakter azt jelöli, hogy az elemből nulla vagy több példány fordulhat elő a dokumentumban.
* '''ismétlődés''': egy karakter, amely azt a tételt követi, amelyre vonatkozik. Meghatározza, hogy az adott tétel hányszor fordulhat elő egymás után az elem meghatározott pontján.
** nincs szimbólum: az tétel pontosan egyszer szerepel
** <tt>+</tt> az adat legalább egyszer szerepel
** <tt>*</tt> az adat egyszer, többször, vagy egyszer sem fordul elő
** <tt>?</tt> az adat egyszer vagy egyszer sem jelenik meg
* <tt>EMPTY</tt>: az elemnek egyáltalán nem lehet tartalma, még szöveg sem.
* <tt>ANY</tt>: az elem bármilyen tartalmat megenged korlátozás nélkül. Bármennyi gyermek-eleme lehet, beleértve a szöveges tartalmat is.
 
=== Attribute list declarations ===