whiteSpace

WhiteSpace processing is a contentious area of XML and is one of the main reasons why round-tripping XML produces an output that is (semantically) equivalent rather than (lexically) identical to the original. The following example demonstrates three ways to control whitespace processing. It inlcudes an element 'foobar' with liberally spaced mixed content interspersed with sub-elements 'foo' and 'bar' both with content containing leading (tabbed) indentation.

The whitespace processing of element 'foo' is determined by the xml:space attribute which indicates that whitespace should be collapsed; trimming the leading whitespace. The whitespace processing of element 'bar' is determined by the 'whiteSpace' restriction in the schema, which is also set to collapse whitespace.

<?xml version="1.0" encoding="UTF-8"?>
<foobar xmlns="http://example.org/">
        foo
        bar
        <foo xml:space="collapse">
        foo
        </foo>
        
        <bar>
        bar
        </bar>
        foo             bar
</foobar>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://example.org/" xmlns="http://example.org/">

        <xs:element name="foobar">
        <xs:complexType mixed="true">
                <xs:sequence>
                        <xs:element ref="foo" />
                        <xs:element ref="bar" />
                </xs:sequence>
        </xs:complexType>
        </xs:element>
        
        <xs:element name="foo" type="xs:string" />
        
        <xs:element name="bar">
                <xs:simpleType>
                        <xs:restriction base="xs:string">
                                <xs:whiteSpace value="collapse" />
                        </xs:restriction>
                </xs:simpleType>
        </xs:element>
        
</xs:schema>

Finally, the gloze parameter space may be set to 'preserve' or 'default', equivalent to setting xml:space in the document element. Mapping to RDF with space=default, then round-tripping back into XML we get the following (equivalenmt but not identical to the original).

<?xml version="1.0" encoding="UTF-8"?>
<ns1:foobar xmlns:ns1="http://example.org/">foo bar<ns1:foo>foo</ns1:foo>
    <ns1:bar>bar</ns1:bar>foo bar</ns1:foobar>

Generated on Mon Jun 18 16:02:38 2007 for Gloze by  doxygen 1.5.0