Well-formed element
Encyclopedia
In web page design, and generally for all markup languages such as SGML, HTML
, and XML
, a well-formed element is one that is either
For example, in HTML:word is a well-formed element, while word is not, since the bold element is not closed. In XHTML, empty elements (elements that inherently have no content) should be closed by putting a slash at the end of the opening tag, e.g. ,
,
, etc. In HTML, there is no closing tag for such elements, and no slash is added to the opening tag.
In a well-formed document,
For example, the code below is not well-formed HTML, because the em and strong elements overlap:
In XML
, the phrase well-formed document
is often used to describe a text that follows all the syntactic rules labelled as well-formedness rules in the XML specification: strictly speaking the phrase is tautological, since a text that does not follow these rules is not an XML document. The rules for well-formedness go beyond the requirements mentioned above to nest tags properly and to quote attribute values: they include, for example, rules about the characters that can appear in names and elsewhere, the syntax of comments, processing instruction
s, entity references, and CDATA sections, and many other similar details. Sometimes the adjective well-formed is used to contrast with valid: a valid XML document is one that is not only well-formed, but also conforms to the grammar defined in its own DTD (Document Type Definition
).
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....
, and XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
, a well-formed element is one that is either
- opened and subsequently closed,
- an empty element, which in that case must be terminated,
- properly nested so that it does not overlap.
For example, in HTML:
In a well-formed document,
- all elements are well-formed, and
- a single element, known as the root elementRoot elementEach XML document has exactly one single root element. This element is also known as the document element. It encloses all the other elements and is therefore the sole parent element to all the other elements....
, contains all of the other elements in the document.
For example, the code below is not well-formed HTML, because the em and strong elements overlap:
In XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
, the phrase well-formed document
Well-formed document
A well-formed document in XML is a document that adheres to the syntax rules specified by the XML 1.0 specification in that it must satisfy both physical and logical structures."-Requirements:At its base level well-formed documents require that:...
is often used to describe a text that follows all the syntactic rules labelled as well-formedness rules in the XML specification: strictly speaking the phrase is tautological, since a text that does not follow these rules is not an XML document. The rules for well-formedness go beyond the requirements mentioned above to nest tags properly and to quote attribute values: they include, for example, rules about the characters that can appear in names and elsewhere, the syntax of comments, processing instruction
Processing Instruction
A Processing Instruction is an SGML and XML node type, which may occur anywhere in the document, intended to carry instructions to the application....
s, entity references, and CDATA sections, and many other similar details. Sometimes the adjective well-formed is used to contrast with valid: a valid XML document is one that is not only well-formed, but also conforms to the grammar defined in its own DTD (Document Type Definition
Document Type Definition
Document Type Definition is a set of markup declarations that define a document type for SGML-family markup languages...
).