Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Spaces in element? (http://www.velocityreviews.com/forums/t562248-spaces-in-element.html)

Gus Gassmann 12-19-2007 10:48 AM

Spaces in element?
 
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: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>

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.


Pavel Lepin 12-19-2007 12:54 PM

Re: Spaces in element?
 

Gus Gassmann <Horand.Gassmann@dal.ca> wrote in
<3607ac47-5bf5-457f-aee7-85c9e16bd4af@s8g2000prg.googlegroups.com>:
> <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.

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.

Gus Gassmann 12-19-2007 01:49 PM

Re: Spaces in element?
 
On Dec 19, 12:54 pm, Pavel Lepin <p.le...@ctncorp.com> wrote:
> Gus Gassmann <Horand.Gassm...@dal.ca> wrote in
> <3607ac47-5bf5-457f-aee7-85c9e16bd...@s8g2000prg.googlegroups.com>:
>
>
>
>
>
> > <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.


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

Pavel Lepin 12-19-2007 02:05 PM

Re: Spaces in element?
 

Gus Gassmann <Horand.Gassmann@dal.ca> wrote in
<2fed1409-c9b0-485c-a964-96f928ff1369@s19g2000prg.googlegroups.com>:
> On Dec 19, 12:54 pm, Pavel Lepin <p.le...@ctncorp.com>
> wrote:
>> Gus Gassmann <Horand.Gassm...@dal.ca> wrote:
>> > 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.

>
> 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.

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.

David Carlisle 12-20-2007 12:06 AM

Re: Spaces in element?
 
Gus Gassmann wrote:

> 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



--
http://dpcarlisle.blogspot.com


All times are GMT. The time now is 11:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.