Spaces in element?

G

Gus Gassmann

A group of us is building a parser for a w3c schema and have some
interpretation question concerning whitespace in an element.

The definition is as follows:

<xs:complexType name="OSnLNodeNumber">
<xs:complexContent>
<xs:attribute name="type" use="optional" default="real">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="real"/>
<xs:enumeration value="string"/>
<xs:enumeration value="realtime"/>
<xs:enumeration value="random"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="id" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="number" type="OSnLNodeNumber"
substitutionGroup="OSnLNode"/>

This is used in an XML file as follows:

<number type="real" value="1.0"/>
<number type="real" value="2.0"></number>
<number type="real" value="3.0"> </number>

Both XMLSpy and Xerces parse the first two numbers, but not the third.
XMLSpy gives the error message:

"The content of complextype definition 'OSnLNodeNumber' is 'empty'.
This forbids any content for element <number>."

Some of us say that whitespace should not matter, particularly if I
want to say

<number type="real" value="4.0">
</number>

Anyone know the official w3c position on this? Can you quote chapter
and verse or point us into the right direction?

Thanks a million.
 
P

Pavel Lepin

Gus Gassmann said:
<xs:complexType name="OSnLNodeNumber">
<xs:complexContent>
<xs:extension base="OSnLNode">
<xs:attribute name="value" type="xs:string"
use="optional"/
<xs:attribute name="type" use="optional"
default="real">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="real"/>
<xs:enumeration value="string"/>
<xs:enumeration value="realtime"/>
<xs:enumeration value="random"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="id" type="xs:string"
use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="number" type="OSnLNodeNumber"
substitutionGroup="OSnLNode"/>

This is used in an XML file as follows:

<number type="real" value="1.0"/>
<number type="real" value="2.0"></number>
<number type="real" value="3.0"> </number>

Some of us say that whitespace should not matter,
particularly if I want to say

<number type="real" value="4.0">
</number>

Anyone know the official w3c position on this? Can you
quote chapter and verse or point us into the right
direction?

Googling for 'schema empty content whitespace' has lead me
to XML Schema 1.0, Structures, 3.4.4, 2.1, which indicates
that only the first two of your examples are valid
according to your definition.
 
G

Gus Gassmann

<[email protected]>:












Googling for 'schema empty content whitespace' has lead me
to XML Schema 1.0, Structures, 3.4.4, 2.1, which indicates
that only the first two of your examples are valid
according to your definition.

Hmmmh. Now, suppose I _do_ want to allow whitespace (but no other
content, in particular no children). Is there a way to do that?
 
P

Pavel Lepin

Gus Gassmann said:
Hmmmh. Now, suppose I _do_ want to allow whitespace (but
no other content, in particular no children). Is there a
way to do that?

Do not use empty content. Restrict xs:string using a pattern
to match whitespace-only strings and nothing else. Then
extend that.
 
D

David Carlisle

Gus said:
Some of us say that whitespace should not matter, particularly if I
want to say

<number type="real" value="4.0">
</number>

Anyone know the official w3c position on this? Can you quote chapter
and verse or point us into the right direction?

Thanks a million.
The element is non empty, so doesn't match the schema as specified, you
would have to define the type to allow text content, restricted with a
pattern to white space if you want to allow white space text.

xml spec, section 2.10

An XML processor MUST always pass all characters in a document that are
not markup through to the application. A validating XML processor MUST
also inform the application which of these characters constitute white
space appearing in element content.

so your parser can not just silently drop indentation space, and so the
document doesn't validate. The parsers of a certain well known
corporation don't actually follow this requirement and (by default)
throw away white space anyway, but the spec is fairly clear that they
should not do that...

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top