Common Lisp Package: S-XML

A simple XML parser with an efficient, purely functional, event-based interface as well as a DOM interface

README:

FUNCTION

Public

EXTEND-NAMESPACES (ATTRIBUTES NAMESPACES)

Given possible 'xmlns[:prefix]' attributes, extend the namespaces bindings

FIND-NAMESPACE (URI)

Find a registered XML namespace identified by uri

FIRST-XML-ELEMENT-CHILD (XML-ELEMENT)

Get the first child of an xml-element

MAKE-XML-ELEMENT (&KEY ((NAME DUM0) NIL) ((ATTRIBUTES DUM1) NIL) ((CHILDREN DUM2) NIL))

Make and return a new xml-element struct

NEW-XML-ELEMENT (NAME &REST CHILDREN)

Make a new xml-element with name and children

PARSE-ATTRIBUTE-NAME (STRING)

Default parser for the attribute name

PARSE-ATTRIBUTE-VALUE (NAME STRING)

Default parser for the attribute value

PARSE-XML (STREAM &KEY (OUTPUT-TYPE LXML))

Parse a character stream as XML and generate a DOM of output-type, defaulting to :lxml

PARSE-XML-FILE (FILENAME &KEY (OUTPUT-TYPE LXML))

Parse a character file as XML and generate a DOM of output-type, defaulting to :lxml

PARSE-XML-STRING (STRING &KEY (OUTPUT-TYPE LXML))

Parse a string as XML and generate a DOM of output-type, defaulting to :lxml

REGISTER-NAMESPACE (URI PREFIX PACKAGE)

Register a new or redefine an existing XML namespace defined by uri with prefix and package

RESOLVE-IDENTIFIER (IDENTIFIER NAMESPACES &OPTIONAL AS-ATTRIBUTE)

Resolve the string identifier in the list of namespace bindings

SPLIT-IDENTIFIER (IDENTIFIER)

Split an identifier 'prefix:name' and return (values prefix name)

START-PARSE-XML (STREAM &OPTIONAL (STATE (MAKE-INSTANCE 'XML-PARSER-STATE)))

Parse and return a toplevel XML element from stream, using parser state

XML-ELEMENT-ATTRIBUTE (XML-ELEMENT KEY)

Return the string value of the attribute with name the keyword :key of xml-element if any, return null if not found

SETFXML-ELEMENT-ATTRIBUTE (VALUE XML-ELEMENT KEY)

Set the string value of the attribute with name the keyword :key of xml-element, creating a new attribute if necessary or overwriting an existing one, returning the value

XML-ELEMENT-ATTRIBUTES (INSTANCE)

Return the alist of attribute names and values dotted pairs from an xml-element struct

XML-ELEMENT-CHILDREN (INSTANCE)

Return the list of children from an xml-element struct

XML-ELEMENT-NAME (INSTANCE)

Return the name from an xml-element struct

XML-ELEMENT-P (OBJECT)

Return T when the argument is an xml-element struct

Undocumented

SETFXML-ELEMENT-ATTRIBUTES (NEW-VALUE INSTANCE)

SETFXML-ELEMENT-CHILDREN (NEW-VALUE INSTANCE)

SETFXML-ELEMENT-NAME (NEW-VALUE INSTANCE)

Private

FIND-NAMESPACE-BINDING (PREFIX NAMESPACES)

Find the XML namespace currently bound to prefix in the namespaces bindings

IDENTIFIER-CHAR-P (CHAR)

Is char an XML identifier character ?

MAKE-EXTENDABLE-STRING (&OPTIONAL (SIZE 10))

Make an extendable string which is a one-dimensional character array which is adjustable and has a fill pointer

MAKE-STANDARD-ENTITIES

A hashtable mapping XML entity names to their replacement strings, filled with the standard set

NEW-NAMESPACE (URI &OPTIONAL PREFIX)

Register a new namespace for uri and prefix, creating a package if necessary

PARSE-IDENTIFIER (STREAM IDENTIFIER)

Read and returns an XML identifier from stream, positioned at the start of the identifier, ending with the first non-identifier character, which is peeked, the identifier is written destructively into identifier which is also returned

PARSE-STRING (STREAM STATE STRING)

Read and return an XML string from stream, delimited by either single or double quotes, the stream is expected to be on the opening delimiter, at the end the closing delimiter is also read, entities are resolved, eof before end of string is an error

PARSE-TEXT (STREAM STATE EXTENDABLE-STRING)

Read and collect XML text from stream in string which is destructively modified, the text ends with a '<', which is peeked and returned, entities are resolved, eof is considered an error

PARSE-WHITESPACE (STREAM EXTENDABLE-STRING)

Read and collect XML whitespace from stream in string which is destructively modified, return first non-whitespace character which was peeked but not read, return #Null on eof

PARSE-XML-ELEMENT (STREAM STATE)

Parse and return an XML element from stream, positioned after the opening '<'

PARSE-XML-ELEMENT-ATTRIBUTES (STREAM STATE)

Parse XML element attributes from stream positioned after the tag identifier, returning the attributes as an assoc list, ending at either a '>' or a '/' which is peeked and also returned

READ-CDATA (STREAM STATE STRING)

Reads in the CDATA and calls the callback for CDATA if it exists

RESOLVE-ENTITY (STREAM EXTENDABLE-STRING ENTITIES ENTITY)

Read and resolve an XML entity from stream, positioned after the '&' entity marker, accepting &name; &#DEC; and &#xHEX; formats, destructively modifying string, which is also returned, destructively modifying entity, incorrect entity formats result in errors

SKIP-COMMENT (STREAM)

Skip an XML comment in stream, positioned after the opening '<!--', consumes the closing '-->' sequence, unexpected eof or a malformed closing sequence result in a error

SKIP-SPECIAL-TAG (STREAM STATE)

Skip an XML special tag (comments and processing instructions) in stream, positioned after the opening '<', unexpected eof is an error

SKIP-WHITESPACE (STREAM)

Skip over XML whitespace in stream, return first non-whitespace character which was peeked but not read, return nil on eof

WHITESPACE-CHAR-P (CHAR)

Is char an XML whitespace character ?

Undocumented

COPY-XML-ELEMENT (INSTANCE)

LXML-FINISH-ELEMENT-HOOK (NAME ATTRIBUTES PARENT-SEED SEED)

LXML-NEW-ELEMENT-HOOK (NAME ATTRIBUTES SEED)

LXML-TEXT-HOOK (STRING SEED)

PARSER-ERROR (MESSAGE &OPTIONAL ARGS STREAM)

PLIST->ALIST (PLIST)

STANDARD-FINISH-ELEMENT-HOOK (NAME ATTRIBUTES PARENT-SEED SEED)

STANDARD-NEW-ELEMENT-HOOK (NAME ATTRIBUTES SEED)

STANDARD-TEXT-HOOK (STRING SEED)

SXML-FINISH-ELEMENT-HOOK (NAME ATTRIBUTES PARENT-SEED SEED)

SXML-NEW-ELEMENT-HOOK (NAME ATTRIBUTES SEED)

SXML-TEXT-HOOK (STRING SEED)

XML-EQUAL (XML-1 XML-2)

GENERIC-FUNCTION

Public

PARSE-XML-DOM (STREAM OUTPUT-TYPE)

Parse a character stream as XML and generate a DOM of output-type

XML-PARSER-ERROR-ARGS (CONDITION)

Get the error arguments from an XML parser error

XML-PARSER-ERROR-MESSAGE (CONDITION)

Get the message from an XML parser error

XML-PARSER-ERROR-STREAM (CONDITION)

Get the stream from an XML parser error

SLOT-ACCESSOR

Public

GET-ENTITIES (OBJECT)

A hashtable mapping XML entity names to their replacement stings

SETFGET-ENTITIES (NEW-VALUE OBJECT)

A hashtable mapping XML entity names to their replacement stings

GET-FINISH-ELEMENT-HOOK (OBJECT)

Called when element ends

SETFGET-FINISH-ELEMENT-HOOK (NEW-VALUE OBJECT)

Called when element ends

GET-NEW-ELEMENT-HOOK (OBJECT)

Called when new element starts

SETFGET-NEW-ELEMENT-HOOK (NEW-VALUE OBJECT)

Called when new element starts

GET-PACKAGE (OBJECT)

The Common Lisp package where this namespace's symbols are interned

SETFGET-PACKAGE (NEW-VALUE OBJECT)

The Common Lisp package where this namespace's symbols are interned

GET-PREFIX (OBJECT)

The preferred prefix assigned to this namespace

SETFGET-PREFIX (NEW-VALUE OBJECT)

The preferred prefix assigned to this namespace

GET-SEED (OBJECT)

The user seed object

SETFGET-SEED (NEW-VALUE OBJECT)

The user seed object

GET-TEXT-HOOK (OBJECT)

Called when text is found

SETFGET-TEXT-HOOK (NEW-VALUE OBJECT)

Called when text is found

GET-URI (OBJECT)

The URI used to identify this namespace

SETFGET-URI (NEW-VALUE OBJECT)

The URI used to identify this namespace

Private

GET-BUFFER (OBJECT)

Reset and return the main reusable buffer

SETFGET-BUFFER (NEW-VALUE OBJECT)

The main reusable character buffer

GET-MINI-BUFFER (OBJECT)

Reset and return the reusable mini buffer

SETFGET-MINI-BUFFER (NEW-VALUE OBJECT)

The secondary, smaller reusable character buffer

VARIABLE

Public

*ATTRIBUTE-NAME-PARSER*

Called to compute interned attribute name from a buffer that will be reused

*ATTRIBUTE-VALUE-PARSER*

Called to compute an element of an attribute list from a buffer that will be reused

*AUTO-CREATE-NAMESPACE-PACKAGES*

If t, new packages will be created for namespaces, if needed, named by the prefix

*AUTO-EXPORT-SYMBOLS*

If t, export newly interned symbols form their packages

*IGNORE-NAMESPACES*

When t, namespaces are ignored like in the old version of S-XML

*LOCAL-NAMESPACE*

The local (global default) XML namespace

*NAMESPACES*

Ordered list of (prefix . XML-namespace) bindings currently in effect - special variable

*REQUIRE-EXISTING-SYMBOLS*

If t, each XML identifier must exist as symbol already

Private

*KNOWN-NAMESPACES*

The list of known/defined namespaces

*XML-NAMESPACE*

REC-xml-names-19990114 says the prefix xml is bound to the namespace http://www.w3.org/XML/1998/namespace.

CLASS

Public

XML-PARSER-STATE

The XML parser state passed along all code making up the parser

Private

XML-NAMESPACE

Describes an XML namespace and how it is handled

Undocumented

XML-ELEMENT

CONDITION

Public

XML-PARSER-ERROR

Thrown by the XML parser to indicate errorneous input