4.2. Namespaces in SXML

XSieve supports the both forms of the SXML representation of namespaces: with prefix and with URI.

Example 6. Different kinds of presentation of namespaces

XML fragment:

<foo:bar xmlns:foo="http://xsieve.sourceforge.net/foo"/>

SXML using prefixes

  (@ (@ (*NAMESPACES* (foo "http://xsieve.sourceforge.net/foo")))))

SXML using URIs

  (@ (@ (*NAMESPACES* (http://xsieve.sourceforge.net/foo
    "http://xsieve.sourceforge.net/foo" foo)))))

The form with prefix is preferred. Moreover, automatic conversion from XML to SXML always produces the form with prefix.

To represent a default namespace, XSieve uses the optional original-prefix feature of SXML. The value of the original prefix is the symbol *DEFAULT*.

Example 7. Representing a default namespace

XML fragment:

<foo xmlns="http://xsieve.sourceforge.net/foo">

SXML fragment:

      (@ (@ (*NAMESPACES* (z "http://xsieve.sourceforge.net/foo" *DEFAULT*))))

The danger of the form with prefix is that the prefixes can be "hanging".

Example 8. SXML with hanging prefixes

(hang:foo (hang:bar))

Manipulating SXML fragments with hanging prefixes, one can create an incorrect output document. Possible errors:

It's task of an XSieve developer to avoid such problems. XSieve doesn't try to prevent them.

Fortunately, hanging prefixes are not so bad. XSieve tries to resolve the prefixes when converting from SXML to XML. Such conversion is usually performed when XSieve have finished execution of Scheme code and going to put the result to the output tree. It is very likely that the output tree has a namespace declaration for the prefix.

As a summary, here is a set of guidelines for using namespaces.