Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
XML
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Schemas and validation == In addition to being well formed, an XML document may be ''valid''. This means that it contains a reference to a [[Document Type Definition]] (DTD), and that its elements and attributes are declared in that DTD and follow the grammatical rules for them that the DTD specifies. XML processors are classified as ''validating'' or ''non-validating'' depending on whether or not they check XML documents for validity.{{sfnp|Harold|Means|2002|p=8}} A processor that discovers a validity error must be able to report it, but may continue normal processing. A DTD is an example of a ''[[XML schema|schema]]'' or ''grammar''. Since the initial publication of XML 1.0, there has been substantial work in the area of schema languages for XML. Such schema languages typically constrain the set of elements that may be used in a document, which attributes may be applied to them, the order in which they may appear, and the allowable parent/child relationships. === Document type definition === {{Main|Document type definition}} The oldest schema language for XML is the [[document type definition]] (DTD), inherited from SGML. DTDs have the following benefits: * DTD support is ubiquitous due to its inclusion in the XML 1.0 standard. * DTDs are terse compared to element-based schema languages and consequently present more information in a single screen. * DTDs allow the declaration of [[SGML entity|standard public entity sets]] for publishing characters. * DTDs define a ''document type'' rather than the types used by a namespace, thus grouping all constraints for a document in a single collection. DTDs have the following limitations: * They have no explicit support for newer [[feature (software design)|features]] of XML, most importantly [[XML Namespace|namespaces]]. * They lack expressiveness. XML DTDs are simpler than SGML DTDs and there are certain structures that cannot be expressed with regular grammars. DTDs only support rudimentary datatypes. * They lack readability. DTD designers typically make heavy use of parameter entities (which behave essentially as textual [[macro (computer science)|macros]]), which make it easier to define complex grammars, but at the expense of clarity. * They use a syntax based on [[regular expression]] syntax, inherited from SGML, to describe the schema. Typical XML APIs such as [[Simple API for XML|SAX]] do not attempt to offer applications a structured representation of the syntax, so it is less accessible to programmers than an element-based syntax may be. Two peculiar features that distinguish DTDs from other schema types are the syntactic support for embedding a DTD within XML documents and for defining ''entities'', which are arbitrary fragments of text or markup that the XML processor inserts in the DTD itself and in the XML document wherever they are referenced, like character escapes. DTD technology is still used in many applications because of its ubiquity. === Schema === {{Main|XML Schema (W3C)}} A newer schema language, described by the W3C as the successor of DTDs, is [[XML Schema (W3C)|XML Schema]], often referred to by the [[initialism]] for XML Schema instances, XSD (XML Schema Definition). XSDs are far more powerful than DTDs in describing XML languages. They use a rich [[Data type|datatyping]] system and allow for more detailed constraints on an XML document's logical structure. XSDs also use an XML-based format, which makes it possible to use ordinary XML tools to help process them. xs:schema element that defines a schema: <syntaxhighlight lang="xml"> <?xml version="1.0" encoding="UTF-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"></xs:schema> </syntaxhighlight> === RELAX NG === {{Main|RELAX NG}} [[RELAX NG]] (Regular Language for XML Next Generation) was initially specified by [[OASIS (organization)|OASIS]] and is now a standard (Part 2: ''Regular-grammar-based validation'' of [[DSDL|ISO/IEC 19757 β DSDL]]). RELAX NG schemas may be written in either an XML based syntax or a more compact non-XML syntax; the two syntaxes are [[isomorphic]] and [[James Clark (programmer)|James Clark]]'s conversion toolβ[http://www.thaiopensource.com/relaxng/trang.html Trang]βcan convert between them without loss of information. RELAX NG has a simpler definition and validation framework than XML Schema, making it easier to use and implement. It also has the ability to use [[datatype]] framework [[Plug-in (computing)|plug-ins]]; a RELAX NG schema author, for example, can require values in an XML document to conform to definitions in XML Schema Datatypes. === Schematron === [[Schematron]] is a language for making [[assertion (computing)|assertions]] about the presence or absence of patterns in an XML document. It typically uses [[XPath]] expressions. Schematron is now a standard (Part 3: ''Rule-based validation'' of [[DSDL|ISO/IEC 19757 β DSDL]]). === DSDL and other schema languages === [[DSDL]] (Document Schema Definition Languages) is a multi-part ISO/IEC standard (ISO/IEC 19757) that brings together a comprehensive set of small schema languages, each targeted at specific problems. DSDL includes [[RELAX NG]] full and compact syntax, [[Schematron]] assertion language, and languages for defining datatypes, character repertoire constraints, renaming and entity expansion, and namespace-based [[routing]] of document fragments to different validators. DSDL schema languages do not have the vendor support of XML Schemas yet, and are to some extent a grassroots reaction of industrial publishers to the lack of utility of XML Schemas for [[publishing]]. Some schema languages not only describe the structure of a particular XML format but also offer limited facilities to influence processing of individual XML files that conform to this format. DTDs and XSDs both have this ability; they can for instance provide the [[infoset]] augmentation facility and attribute defaults. RELAX NG and Schematron intentionally do not provide these.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)