next up previous contents index
Next: 20. Notifications Up: II. Widget Commands Previous: 18. Document related commands   Contents   Index


19. XML support

The sgml widget supports editing of conforming XML documents with or without a DTD. When a document is loaded into the sgml widget (or when a new document is created with the pcrmnew command), the document prolog is scanned for an XML declaration of the form <?xml version="1.0" ...?>.

When an XML declaration is found, the sgml widget enters XML mode. In this mode, the behaviour of the widget is slightly different from the normal behaviour in SGML mode. The following sections describe these differences in more detail.

19.1 Differences between SGML and XML mode

When the sgml widget discovers an XML declaration at the beginning of a document, it switches to XML mode and processes the remainder of the document in this mode. If a document does not begin with a proper XML declaration, the widget assumes that the document is an SGML document and uses SGML mode for all operations on the document.



The mode command


mode
  Returns a description of the current widget mode as a proper Tcl list.


The current widget mode can be retrievd by using the pcrmmode widget command. The pcrmmode widget command has the general form


pathname mode

and returns a Tcl list with two elements. The first element of the returned list is either XML or SGML, depending on the current mode of the sgml widget.

The second element in the list returned by the mode command is one of the keywords valid or wellformed, depending on whether a DTD was found in the document or not. wellformed means that the document is 'only' a DTDless document that is a well-formed XML document with no explicit description of the available markup. valid means that the document contains (or points to) a DTD that canbe used for validating the document (it does not necessarily mean that the current state of the document instance completely satisfies the validity requirements of the DTD).

The sgml widget can handle DTDless documents only in XML mode since all SGML documents must contain (or point to) a DTD describing the document structure. Hence, the mode command will never return the result SGML wellformed.

\epsfbox{images/attn.eps} You can not change the widget mode by means of the mode command. Mode selection happens automatically, depending on the detection of a XML declaration at the beginning of the document prolog.

19.2 DTDless and valid XML documents

Since XML documents come in two flavours, the sgml widget has to distinguish between DTDless and valid XML documents. The main difference between the handling of well-formed and valid XML documents relates to the process of loading (or creating) a document. Since DTDless documents do not define the available elements and their content, the sgml widget implicitly declares all elements that occur in a DTDless document with a content type of ANY.19.1

Attributes that occur for elements in DTDless documents are silently defined for these elements with a declared value of CDATA and a default value of IMPLIED.

19.2.1 Additional commands for XML documents

For SGML and valid XML documents, the DTD determines the operations that are allowed on the document. For DTDless XML documents, however, this information is not available.



Commands for DTDless XML documents


element declare name ?name ...?
  Declares one or more new XML elements name with a declared content of ANY
attribute declare element name ?name...?
  Declares one or more new attributes with a declared value of CDATA for an existing XML element




Footnotes

...ANY@ANY.19.1
In theory, it would be possible to detect empty elements by the usage of the /> notation. However, empty elements can be written with a normal end tag as well, so the sgml widget does not rely on any heuristics for detecting empty elements.

next up previous contents index
Next: 20. Notifications Up: II. Widget Commands Previous: 18. Document related commands   Contents   Index
TkSGML Reference Manual