473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

NULL Value in XML Schema

Hi All,
How to define an XML element with no value and no attribute?

<X>
<Y/>
</X>

And Y has no value?

I've done it with:

<xsi:element name="Y" type="rn:T_NULL"/>

<xsi:simpleType name="rn:T_NULL">
<xsi:restriction base="xsi:string" length="0"/>
</xsi:simpleType>

But it seems too complicated.
Thanks, Reuven
Mar 16 '06 #1
4 2338


Reuven Nisser wrote:

How to define an XML element with no value and no attribute?

<X>
<Y/>
</X>

And Y has no value?

I've done it with:

<xsi:element name="Y" type="rn:T_NULL"/>

<xsi:simpleType name="rn:T_NULL">
<xsi:restriction base="xsi:string" length="0"/>
</xsi:simpleType>


The W3C XML schema language offers e.g.

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">

<xs:element name="Y" type="xs:string" nillable="true" />

then in the instance document you would need e.g.

<Y xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true" />

see
<http://www.w3.org/TR/xmlschema-0/#Nils

But that is a mechansism provided more to cater for the possibility that
you can have some Y elements that have contents and some others that
don't have content (have null or nil contents).
If you really want to have all occurences of Y to have no contents then
I guess your approach is fine.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 16 '06 #2
Thanks for Martin's informative inputs.

Hi Reuven,

The nillable="true" and xsi:nil="true" is the standard approach to mark
an element as null value in XML document. However, for your scenario, if
you want the element always be null value(actually it is called an empty
element), we still need to use the complex type definition to restrict the
type's content. In addition to the means you currently use, you can also
have a look at the following article which mentioned some other definition
for empty element in XSD:

#XSD Complex Empty Elements
http://www.w3schools.com/schema/sche...plex_empty.asp

Hope this also helps some.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Mar 17 '06 #3
Hi Steven,
Thanks, this is the answer I was looking for :

<xsi:complexType name="T_NULL">
<xsi:annotation><xsi:documentation>No value allowed
here</xsi:documentation></xsi:annotation>
</xsi:complexType>

Regards, Reuven
Mar 18 '06 #4
You're welcome Reuven,

Have a good day!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: eXavier | last post by:
Hi all, I wrote some generator of classes from XSD files but encountred unexpected (for me) values in parsed DOM. First I load XSD with XmlSchema.Read() method, then iterate through...
0
by: richard | last post by:
Hi, I have a Schema for a Dataset which I am populating from Excel. One of the columns is a string datatype. When I Fill the Dataset I want any Null values to be set to a string value. I have...
3
by: Lynn | last post by:
Hi all, I am having problem when did the validation of XML document with Schema. my schema is like the following: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="schema.xsd"...
1
by: Kenny Mullican | last post by:
I am using complex types in order to support serialization/deserialization of floating point numbers, since floating points can't be null. I've seen how to suppress attributes that are "not...
2
by: Pet Matrix. | last post by:
Hi, I am having the schema and one element in that schema is , <xs:element name="EndT" type="TstampType" minOccurs="1" maxOccurs="1"/> How do I represent the NULL value for the datatype dateTime...
0
by: Benny Raymond | last post by:
reply to: benny@pocketrocks.com if possible: I'm trying to set up a hierarchy system in this database where each row can be related to a previous row. The problem is that when I go to...
5
by: CindyRob | last post by:
Using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, Visual Studio .NET 2003, hotfixes 892202 and 823639. I create a proxy class using wsdl.exe, and in the serialized XML request, I see...
13
by: Jiho Han | last post by:
Here's the issue. You have a class, Class Person { public int id; public string firstname; public string lastname; }
5
by: hello | last post by:
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>...
2
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.