RE: optional textnode in element

Hi George,

Thanks for your reply. I guess this would also work:

<xs:element name="test">
	<xs:complexType> 
		<xs:choice> 
			<xs:element>
				<xs:simpleType> 
					<xs:restriction base="xs:integer"> 
				        	<xs:minInclusive value="1"
/>
				                <xs:maxInclusive value="100"
/> 
				        </xs:restriction> 
            			</xs:simpleType 
			</xs:element>
			<xs:element>
				<xs:simpleType>
           				<xs:restriction base="xs:string">
             					<xs:enumeration value=""/>
           				</xs:restriction>
         		</xs:simpleType>
			</xs:element>
		</xs:choice> 
	</xs:complexType> 	
</xs:element> 
            
BTW is there a difference between Union and Choice? Both correspond to a
logical OR.

Thanks,

Chris

> -----Original Message-----
> From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org]
> On Behalf Of George Cristian Bina
> Sent: 19 September 2006 13:52
> To: Christian Setzkorn
> Cc: xmlschema-dev@w3.org
> Subject: Re: optional textnode in element
> 
> 
> Hi Chris,
> 
> You can define your element type as a union of integers from one to 100
> and empty string.
> 
> 
>    <xs:element name="test">
>      <xs:simpleType>
>        <xs:union>
>          <xs:simpleType>
>            <xs:restriction base="xs:integer">
>              <xs:minInclusive value="1"/>
>              <xs:maxInclusive value="100"/>
>            </xs:restriction>
>          </xs:simpleType>
>          <xs:simpleType>
>            <xs:restriction base="xs:string">
>              <xs:enumeration value=""/>
>            </xs:restriction>
>          </xs:simpleType>
>        </xs:union>
>      </xs:simpleType>
>    </xs:element>
> 
> Empty values are not nil in XML Schema. To mark a nil value you should
> use xsi:nil=true where xsi is bound to the schema instance namespace
> http://www.w3.org/2001/XMLSchema-instance.
> 
> If you modify the above example to specify that the element is nillable
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> 
>    <xs:element name="test" nillable="true">
> ...
> 
> then you can have instances like
> 
> nil value:
> 
> <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:nil="true"/>
> 
> enpty value
> 
> <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
> 
> integer value
> 
> <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">10</test>
> 
> You *cannot* have xsi:nil specified and also an integer value like below
> 
> <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:nil="true">10</test>
> 
> Best Regards,
> George
> ---------------------------------------------------------------------
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
> 
> 
> Christian Setzkorn wrote:
> > Hi,
> >
> > How can I define that an elements text node is ‘optional’ for an element
> > like this one:
> >
> > <xs:element>
> >           <xs:simpleType>
> >             <xs:restriction base="xs:integer">
> >               <xs:minInclusive value="1" />
> >               <xs:maxInclusive value="100" />
> >             </xs:restriction>
> >           </xs:simpleType>
> >         </xs:element>
> >
> > So that this:
> >
> > <number>70</number>
> >
> > and this is possible:
> >
> > </number>
> >
> > Any feedback would be very much appreciated. Many thanks.
> >
> > Chris
> >
> > PS: I am also a bit confused about the nil value. Van der Vilst writes
> in
> > his book: “an empty element is not always null, but a null element must
> be
> > empty.” ????
> >
> > Are you aware of articles that may clarify this a bit more? Thanks!
> >
> > BTW: In statistics the whole thing gets even more complicated. I can
> have
> > something like MCAR (missing completely at random), MAR (missing at
> random),
> > MNAR (missing not at random. To model this I would use something like
> this:
> >
> > <?xml version="1.0" encoding="utf-16"?>
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> >   <xs:element name="test">
> >     <xs:complexType>
> >       <xs:choice>
> >         <xs:element>
> >           <xs:simpleType>
> >             <xs:restriction base="xs:integer">
> >               <xs:minInclusive value="1" />
> >               <xs:maxInclusive value="100" />
> >             </xs:restriction>
> >           </xs:simpleType>
> > </xs:element>
> > <xs:element>
> > <xs:simpleType>
> > <	xs:restriction base="xs:NMTOKEN">
> > 		<xs:enumeration value=”MCAR”/>
> > <xs:enumeration value=”MAR”/>
> > <xs:enumeration value=”MNAR”/>
> > 			</xs:restriction>
> > </xs:simpleType>
> >         	</xs:element>
> >       </xs:choice>
> >     </xs:complexType>
> >   </xs:element>
> > </xs:schema>
> >
> > What do you think?
> >
> >
> >
> >
> 
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.405 / Virus Database: 268.12.5/450 - Release Date: 18/09/2006
> 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.12.5/450 - Release Date: 18/09/2006
 

Received on Tuesday, 19 September 2006 13:09:54 UTC