From 968041a8b2ec86c39b5074024ce97d136ecd9a95 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 26 Oct 2006 11:17:37 +0200 Subject: Load /tmp/libxml2-2.6.27 into libxml2/branches/upstream/current. --- doc/xmldtd.html | 154 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 77 insertions(+), 77 deletions(-) (limited to 'doc/xmldtd.html') diff --git a/doc/xmldtd.html b/doc/xmldtd.html index 3f5a797..c5541d6 100644 --- a/doc/xmldtd.html +++ b/doc/xmldtd.html @@ -17,84 +17,84 @@ A:link, A:visited, A:active { text-decoration: underline }
  • Some examples
  • How to validate
  • Other resources
  • -

    General overview

    Well what is validation and what is a DTD ?

    DTD is the acronym for Document Type Definition. This is a -descriptionofthe content for a family of XML files. This is part of the -XML1.0specification, and allows one to describe and verify that a -givendocumentinstance conforms to the set of rules detailing its structure -andcontent.

    Validation is the process of checking a document against a -DTD(moregenerally against a set of construction rules).

    The validation process and building DTDs are the two most difficultpartsof -the XML life cycle. Briefly a DTD defines all the possible elementsto befound -within your document, what is the formal shape of your documenttree(by -defining the allowed content of an element; either text, aregularexpression -for the allowed list of children, or mixed content i.e.both textand -children). The DTD also defines the valid attributes for allelements andthe -types of those attributes.

    The definition

    The W3C XML Recommendation(Tim Bray's annotated -versionofRev1):

    (unfortunately) all this is inherited from the SGML world, the -syntaxisancient...

    Simple rules

    Writing DTDs can be done in many ways. The rules to build them if -youneedsomething permanent or something which can evolve over time can -beradicallydifferent. Really complex DTDs like DocBook ones are flexible -butquiteharder to design. I will just focus on DTDs for a formats with a -fixedsimplestructure. It is just a set of basic rules, and definitely -notexhaustive norusable for complex DTD design.

    How to reference a DTD from a document:

    Assuming the top element of the document is specand the -dtdisplaced in the file mydtdin the -subdirectorydtdsofthe directory from where the document were -loaded:

    <!DOCTYPE spec SYSTEM "dtds/mydtd">

    Notes:

    Declaring elements:

    The following declares an element spec:

    <!ELEMENT spec (front, body, back?)>

    It also expresses that the spec element contains onefront,one -bodyand one optionalbackchildren elements inthis -order. The declaration of oneelement of the structure and its contentare done -in a single declaration.Similarly the following -declaresdiv1elements:

    <!ELEMENT div1 (head, (p | list | note)*, div2?)>

    which means div1 contains one headthen a series -ofoptionalp, lists and notes and -thenanoptional div2. And last but not least an element -cancontaintext:

    <!ELEMENT b (#PCDATA)>

    bcontains text or being of mixed content (text and -elementsinno particular order):

    <!ELEMENT p (#PCDATA|a|ul|b|i|em)*>

    p can contain text or -a,ul,b, i or -emelements inno particularorder.

    Declaring attributes:

    Again the attributes declaration includes their content definition:

    <!ATTLIST termdef name CDATA #IMPLIED>

    means that the element termdefcan have -anameattribute containing text (CDATA) and which -isoptional(#IMPLIED). The attribute value can also be -definedwithin aset:

    <!ATTLIST list -type(bullets|ordered|glossary)"ordered">

    means listelement have a typeattribute -with3allowed values "bullets", "ordered" or "glossary" and which -defaultto"ordered" if the attribute is not explicitly specified.

    The content type of an attribute can be -text(CDATA),anchor/reference/references(ID/IDREF/IDREFS),entity(ies)(ENTITY/ENTITIES) -orname(s)(NMTOKEN/NMTOKENS). The following -definesthat achapterelement can have an -optionalidattributeof type ID, usable for reference -fromattribute of typeIDREF:

    <!ATTLIST chapter id ID #IMPLIED>

    The last value of an attribute definition can -be#REQUIREDmeaning that the attribute has to be -given,#IMPLIEDmeaning that it is optional, or the default -value(possibly prefixed by#FIXEDif it is the only allowed).

    Notes:

    Some examples

    The directory test/valid/dtds/ in the libxml2 distribution +contains some complex DTD examples. The example in the file +test/valid/dia.xml shows an XML file where the simple DTD is +directly included within the document.

    How to validate

    The simplest way is to use the xmllint program included with libxml. The +--valid option turns-on validation of the files given as input. +For example the following validates a copy of the first revision of the XML +1.0 specification:

    xmllint --valid --noout test/valid/REC-xml-19980210.xml

    the -- noout is used to disable output of the resulting tree.

    The --dtdvalid dtd allows validation of the document(s) +against a given DTD.

    Libxml2 exports an API to handle DTDs and validation, check the associated +description.

    Other resources

    DTDs are as old as SGML. So there may be a number of examples on-line, I +will just list one for now, others pointers welcome:

    I suggest looking at the examples found under test/valid/dtd and any of +the large number of books available on XML. The dia example in test/valid +should be both simple and complete enough to allow you to build your own.

    Daniel Veillard

    -- cgit v1.2.3