Previous: , Up: XML Support   [Contents][Index]


14.15.4 XML Structure

The output from the XML parser and the input to the XML output procedure is a complex data structure composed of a hierarchy of typed components. Each component is a record whose fields correspond to parts of the XML structure that the record represents. There are no special operations on these records; each is a tuple with named subparts. The root record type is xml-document, which represents a complete XML document.

Each record type type has the following associated bindings:

<type>

is a variable bound to the record-type descriptor for type. The record-type descriptor may be used as a specializer in SOS method definitions, which greatly simplifies code to dispatch on these types.

type?

is a predicate for records of type type. It accepts one argument, which can be any object, and returns #t if the object is a record of this type, or #f otherwise.

make-type

is a constructor for records of type type. It accepts one argument for each field of type, in the same order that they are written in the type description, and returns a newly-allocated record of that type.

type-field

is an accessor procedure for the field field in records of type type. It accepts one argument, which must be a record of that type, and returns the contents of the corresponding field in the record.

set-type-field!

is a modifier procedure for the field field in records of type type. It accepts two arguments: the first must be a record of that type, and the second is a new value for the corresponding field. The record’s field is modified to have the new value.

record type: xml-document declaration misc-1 dtd misc-2 root misc-3

The xml-document record is the top-level record representing a complete XML document. Declaration is either an xml-declaration object or #f. Dtd is either an xml-dtd object or #f. Root is an xml-element object. Misc-1, misc-2, and misc-3 are lists of miscellaneous items; a miscellaneous item is either an xml-comment object, an xml-processing-instructions object, or a string of whitespace.

record type: xml-declaration version encoding standalone

The xml-declaration record represents the ‘<?xml … ?>’ declaration that optionally appears at the beginning of an XML document. Version is a version string, typically "1.0". Encoding is either an encoding string or #f. Standalone is either "yes", "no", or #f.

record type: xml-element name attributes contents

The xml-element record represents general XML elements; the bulk of a typical XML document consists of these elements. Name is the element name (an XML name). Attributes is a list of XML attribute objects. Contents is a list of the contents of the element. Each element of this list is either a string, an xml-element record or an xml-processing-instructions record.

record type: xml-processing-instructions name text

The xml-processing-instructions record represents processing instructions, which have the form ‘<?name … ?>’. These instructions are intended to contain non-XML data that will be processed by another interpreter; for example they might contain PHP programs. The name field is the processor name (a symbol), and the text field is the body of the instructions (a string).

record type: xml-dtd root external internal

The xml-dtd record represents a document type declaration. The root field is an XML name for the root element of the document. External is either an xml-external-id record or #f. Internal is a list of DTD element records (e.g. xml-!element, xml-!attlist, etc.).

The remaining record types are valid only within a DTD.

record type: xml-!element name content-type

The xml-!element record represents an element-type declaration. Name is the XML name of the type being declared (a symbol). Content-type describes the type and can have several different values, as follows:

record type: xml-!attlist name definitions

The xml-!attlist record represents an attribute-list declaration. Name is the XML name of the type for which attributes are being declared (a symbol). Definitions is a list of attribute definitions, each of which is a list of three elements (name type default). Name is an XML name for the name of the attribute (a symbol). Type describes the attribute type, and can have one of the following values:

Default describes the default value for the attribute, and can have one of the following values:

record type: xml-!entity name value

The xml-!entity record represents a general entity declaration. Name is an XML name for the entity. Value is the entity’s value, either a string or an xml-external-id record.

record type: xml-parameter-!entity name value

The xml-parameter-!entity record represents a parameter entity declaration. Name is an XML name for the entity. Value is the entity’s value, either a string or an xml-external-id record.

record type: xml-unparsed-!entity name id notation

The xml-unparsed-!entity record represents an unparsed entity declaration. Name is an XML name for the entity. Id is an xml-external-id record. Notation is an XML name for the notation.

record type: xml-!notation name id

The xml-!notation record represents a notation declaration. Name is an XML name for the notation. Id is an xml-external-id record.

record type: xml-external-id id uri

The xml-external-id record is a reference to an external DTD. This reference consists of two parts: id is a public ID literal, corresponding to the ‘PUBLIC’ keyword, while uri is a system literal, corresponding to the ‘SYSTEM’ keyword. Either or both may be present, depending on the context. Id is represented as a string, while uri is represented as a URI record.


Previous: , Up: XML Support   [Contents][Index]