By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 909 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

xml schema null or double type

P: n/a
How can I define the schema so that myage element has to be double or
null?

<xs:simpleType name="myage">
<xs:restriction base="xs:double">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

Aug 11 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

You can define that as a union between double and a type that allows
only the null value:

<xs:simpleType name="myage">
<xs:union memberTypes="xs:double">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>

However, XML Schema has support for nillable elements, so if you want
to use this simple type for an element you might consider the
alternative of defining the element nillable. Then in the instance you
just need to add xsi:nil="true" to the element to mark it as having no
value.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

hello wrote:
How can I define the schema so that myage element has to be double or
null?

<xs:simpleType name="myage">
<xs:restriction base="xs:double">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Aug 11 '06 #2

P: n/a
when i use nill=true for the particular element i got the following error.

org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '' is not a valid
value
for 'double'.

when i define the union like this.

<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:double" />
</xs:simpleType>
</xs:union>
</xs:simpleType>

i got this error.

org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.3: '' is not a valid
value
of union type '#AnonType_iims11526672818165646iims11526672557483 110'.

probably i am missing something.

SK
"George Bina" <ge****@oxygenxml.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
Hi,

You can define that as a union between double and a type that allows
only the null value:

<xs:simpleType name="myage">
<xs:union memberTypes="xs:double">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>

However, XML Schema has support for nillable elements, so if you want
to use this simple type for an element you might consider the
alternative of defining the element nillable. Then in the instance you
just need to add xsi:nil="true" to the element to mark it as having no
value.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

hello wrote:
How can I define the schema so that myage element has to be double or
null?

<xs:simpleType name="myage">
<xs:restriction base="xs:double">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

Aug 11 '06 #3

P: n/a
Hi,

In the first case you need
xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
otherwise you just add an attribute from no namespace with the same
local name as the nil attribute from the schema instance namespace.

In the second case I thoght you want the string "null" as value when
you said double or null. If you want the empty string as possible value
replace null from the enumeration value with an empty value:
<xs:enumeration value=""/>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

shuan wrote:
when i use nill=true for the particular element i got the following error.

org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '' is not a valid
value
for 'double'.

when i define the union like this.

<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:double" />
</xs:simpleType>
</xs:union>
</xs:simpleType>

i got this error.

org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.3: '' is not a valid
value
of union type '#AnonType_iims11526672818165646iims11526672557483 110'.

probably i am missing something.

SK
"George Bina" <ge****@oxygenxml.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
Hi,

You can define that as a union between double and a type that allows
only the null value:

<xs:simpleType name="myage">
<xs:union memberTypes="xs:double">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>

However, XML Schema has support for nillable elements, so if you want
to use this simple type for an element you might consider the
alternative of defining the element nillable. Then in the instance you
just need to add xsi:nil="true" to the element to mark it as having no
value.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

hello wrote:
How can I define the schema so that myage element has to be double or
null?
>
<xs:simpleType name="myage">
<xs:restriction base="xs:double">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Aug 12 '06 #4

P: n/a
Thanks, George,
In the first case you need
xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
otherwise you just add an attribute from no namespace with the same
local name as the nil attribute from the schema instance namespace.
I am including this line.
>
In the second case I thoght you want the string "null" as value when
you said double or null. If you want the empty string as possible value
replace null from the enumeration value with an empty value:
<xs:enumeration value=""/>
Event I set to value="" I still get the same error.

"George Bina" <ge****@oxygenxml.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,

In the first case you need
xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
otherwise you just add an attribute from no namespace with the same
local name as the nil attribute from the schema instance namespace.

In the second case I thoght you want the string "null" as value when
you said double or null. If you want the empty string as possible value
replace null from the enumeration value with an empty value:
<xs:enumeration value=""/>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

shuan wrote:
when i use nill=true for the particular element i got the following
error.

org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '' is not a
valid
value
for 'double'.

when i define the union like this.

<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:double" />
</xs:simpleType>
</xs:union>
</xs:simpleType>

i got this error.

org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.3: '' is not a
valid
value
of union type '#AnonType_iims11526672818165646iims11526672557483 110'.

probably i am missing something.

SK
"George Bina" <ge****@oxygenxml.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
Hi,
>
You can define that as a union between double and a type that allows
only the null value:
>
<xs:simpleType name="myage">
<xs:union memberTypes="xs:double">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
>
However, XML Schema has support for nillable elements, so if you want
to use this simple type for an element you might consider the
alternative of defining the element nillable. Then in the instance you
just need to add xsi:nil="true" to the element to mark it as having no
value.
>
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
>
hello wrote:
How can I define the schema so that myage element has to be double
or
null?

<xs:simpleType name="myage">
<xs:restriction base="xs:double">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
>

Aug 14 '06 #5

P: n/a
Hi,

Here it is the full working example:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value=""/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:double"/>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
</xs:schema>

<test></test>

should be reported valid against the above schema.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Shuan wrote:
Thanks, George,
In the first case you need
xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
otherwise you just add an attribute from no namespace with the same
local name as the nil attribute from the schema instance namespace.
I am including this line.

In the second case I thoght you want the string "null" as value when
you said double or null. If you want the empty string as possible value
replace null from the enumeration value with an empty value:
<xs:enumeration value=""/>
Event I set to value="" I still get the same error.

"George Bina" <ge****@oxygenxml.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
Hi,

In the first case you need
xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
otherwise you just add an attribute from no namespace with the same
local name as the nil attribute from the schema instance namespace.

In the second case I thoght you want the string "null" as value when
you said double or null. If you want the empty string as possible value
replace null from the enumeration value with an empty value:
<xs:enumeration value=""/>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

shuan wrote:
when i use nill=true for the particular element i got the following
error.
>
org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: '' is not a
valid
value
for 'double'.
>
when i define the union like this.
>
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:double" />
</xs:simpleType>
</xs:union>
</xs:simpleType>
>
i got this error.
>
org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.3: '' is not a
valid
value
of union type '#AnonType_iims11526672818165646iims11526672557483 110'.
>
probably i am missing something.
>
SK
>
>
"George Bina" <ge****@oxygenxml.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
Hi,

You can define that as a union between double and a type that allows
only the null value:

<xs:simpleType name="myage">
<xs:union memberTypes="xs:double">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>

However, XML Schema has support for nillable elements, so if you want
to use this simple type for an element you might consider the
alternative of defining the element nillable. Then in the instance you
just need to add xsi:nil="true" to the element to mark it as having no
value.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

hello wrote:
How can I define the schema so that myage element has to be double
or
null?
>
<xs:simpleType name="myage">
<xs:restriction base="xs:double">
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Aug 15 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.