Spaces in element?

Discussion in 'XML' started by Gus Gassmann, Dec 19, 2007.

  1. Gus Gassmann

    Gus Gassmann Guest

    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.
    Gus Gassmann, Dec 19, 2007
    #1
    1. Advertising

  2. Gus Gassmann

    Pavel Lepin Guest

    Gus Gassmann <> wrote in
    <>:
    > <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.
    Pavel Lepin, Dec 19, 2007
    #2
    1. Advertising

  3. Gus Gassmann

    Gus Gassmann Guest

    On Dec 19, 12:54 pm, Pavel Lepin <> wrote:
    > Gus Gassmann <> wrote in
    > <>:
    >
    >
    >
    >
    >
    > > <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?
    Gus Gassmann, Dec 19, 2007
    #3
  4. Gus Gassmann

    Pavel Lepin Guest

    Gus Gassmann <> wrote in
    <>:
    > On Dec 19, 12:54 pm, Pavel Lepin <>
    > wrote:
    >> 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?

    >>
    >> 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.
    Pavel Lepin, Dec 19, 2007
    #4
  5. 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
    David Carlisle, Dec 20, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John B. Matthews
    Replies:
    4
    Views:
    651
    John B. Matthews
    Sep 12, 2008
  2. Roedy Green
    Replies:
    3
    Views:
    609
  3. Tomasz Chmielewski

    [CSS] how can I show spaces as spaces?

    Tomasz Chmielewski, Sep 5, 2009, in forum: HTML
    Replies:
    21
    Views:
    1,561
    Jan C. Faerber
    Sep 10, 2009
  4. Tomasz Chmielewski

    how can I show spaces as spaces, part 2

    Tomasz Chmielewski, Sep 9, 2009, in forum: HTML
    Replies:
    14
    Views:
    855
    Jan C. Faerber
    Sep 10, 2009
  5. johkar
    Replies:
    2
    Views:
    2,840
    Mayeul
    Dec 10, 2009
Loading...

Share This Page