HighTechTalks DotNet Forums  

null value in XML

Dotnet XML microsoft.public.dotnet.xml


Discuss null value in XML in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Lynn
 
Posts: n/a

Default null value in XML - 08-16-2004 , 01:23 PM






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"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
elementFormDefault="qualified" targetNamespace="schema.xsd">
<xsd:element name="bookstore" type="bookstoreType" />
<xsd:complexType name="bookstoreType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="book" type="bookType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bookType">
<xsd:sequence>
<xsd:element name="title" type="xsd:string" />
<xsd:element name="author" type="authorName" />
<xsd:element name="price" type="xsd:decimal" />
</xsd:sequence>
<xsd:attribute name="genre" type="xsd:string" />
<xsd:attribute name="publicationdate" type="xsd:string" />
<xsd:attribute name="ISBN" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="authorName">
<xsd:sequence>
<xsd:element name="first-name" type="xsd:string" />
<xsd:element name="last-name" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

and the xml file is:
<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore xmlns = "schema.xsd">
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price></price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<first-name>Sidas</first-name>
<last-name>Plato</last-name>
</author>
<price>9.99</price>
</book>
</bookstore>

when I did the validation, gave me a error saying that
Validation error: The 'schema.xsdrice' element has an invalid
value according to its data type.

I know it is because there is a empty element
<price></price>
in my xml file.
if there any solution to use so that the xml XmlValidatingReader can
recognize the null value?

Thanks.

Lynn






Reply With Quote
  #2  
Old   
Zafar Abbas [MSFT]
 
Posts: n/a

Default Re: null value in XML - 08-16-2004 , 02:23 PM






In the schema put the nillable true attribute on the price element like:

<xsd:element name="price" type="xsd:decimal" nillable="true"/>

and in the XML set the xsi:nil=true but you have to map the xsi namespace
first. Your new XML is:

<bookstore xmlns = "schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price xsi:nil="true"></price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<first-name>Sidas</first-name>
<last-name>Plato</last-name>
</author>
<price>9.99</price>
</book>
</bookstore>


"Lynn" <xiao_lin_zeng (AT) hotmail (DOT) com> wrote

Quote:
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"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
elementFormDefault="qualified" targetNamespace="schema.xsd"
xsd:element name="bookstore" type="bookstoreType" /
xsd:complexType name="bookstoreType"
xsd:sequence maxOccurs="unbounded"
xsd:element name="book" type="bookType" /
/xsd:sequence
/xsd:complexType
xsd:complexType name="bookType"
xsd:sequence
xsd:element name="title" type="xsd:string" /
xsd:element name="author" type="authorName" /
xsd:element name="price" type="xsd:decimal" /
/xsd:sequence
xsd:attribute name="genre" type="xsd:string" /
xsd:attribute name="publicationdate" type="xsd:string" /
xsd:attribute name="ISBN" type="xsd:string" /
/xsd:complexType
xsd:complexType name="authorName"
xsd:sequence
xsd:element name="first-name" type="xsd:string" /
xsd:element name="last-name" type="xsd:string" /
/xsd:sequence
/xsd:complexType
/xsd:schema

and the xml file is:
?xml version='1.0'?
!-- This file represents a fragment of a book store inventory
database --
bookstore xmlns = "schema.xsd"
book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"
title>The Autobiography of Benjamin Franklin</title
author
first-name>Benjamin</first-name
last-name>Franklin</last-name
/author
price></price
/book
book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"
title>The Confidence Man</title
author
first-name>Herman</first-name
last-name>Melville</last-name
/author
price>11.99</price
/book
book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"
title>The Gorgias</title
author
first-name>Sidas</first-name
last-name>Plato</last-name
/author
price>9.99</price
/book
/bookstore

when I did the validation, gave me a error saying that
Validation error: The 'schema.xsdrice' element has an invalid
value according to its data type.

I know it is because there is a empty element
price></price
in my xml file.
if there any solution to use so that the xml XmlValidatingReader can
recognize the null value?

Thanks.

Lynn








Reply With Quote
  #3  
Old   
Lynn
 
Posts: n/a

Default Re: null value in XML - 08-16-2004 , 03:43 PM



Thanks Zafar.
That works.
Is that possible that it can work without
xsi:nil attribute?

thanks.

Lynn


"Zafar Abbas [MSFT]" <zafara (AT) microsoft (DOT) com> wrote

Quote:
In the schema put the nillable true attribute on the price element like:

xsd:element name="price" type="xsd:decimal" nillable="true"/

and in the XML set the xsi:nil=true but you have to map the xsi namespace
first. Your new XML is:

bookstore xmlns = "schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"
title>The Autobiography of Benjamin Franklin</title
author
first-name>Benjamin</first-name
last-name>Franklin</last-name
/author
price xsi:nil="true"></price
/book
book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"
title>The Confidence Man</title
author
first-name>Herman</first-name
last-name>Melville</last-name
/author
price>11.99</price
/book
book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"
title>The Gorgias</title
author
first-name>Sidas</first-name
last-name>Plato</last-name
/author
price>9.99</price
/book
/bookstore


"Lynn" <xiao_lin_zeng (AT) hotmail (DOT) com> wrote in message
news:uWfD8W7gEHA.3476 (AT) tk2msftngp13 (DOT) phx.gbl...
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"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
elementFormDefault="qualified" targetNamespace="schema.xsd"
xsd:element name="bookstore" type="bookstoreType" /
xsd:complexType name="bookstoreType"
xsd:sequence maxOccurs="unbounded"
xsd:element name="book" type="bookType" /
/xsd:sequence
/xsd:complexType
xsd:complexType name="bookType"
xsd:sequence
xsd:element name="title" type="xsd:string" /
xsd:element name="author" type="authorName" /
xsd:element name="price" type="xsd:decimal" /
/xsd:sequence
xsd:attribute name="genre" type="xsd:string" /
xsd:attribute name="publicationdate" type="xsd:string" /
xsd:attribute name="ISBN" type="xsd:string" /
/xsd:complexType
xsd:complexType name="authorName"
xsd:sequence
xsd:element name="first-name" type="xsd:string" /
xsd:element name="last-name" type="xsd:string" /
/xsd:sequence
/xsd:complexType
/xsd:schema

and the xml file is:
?xml version='1.0'?
!-- This file represents a fragment of a book store inventory
database --
bookstore xmlns = "schema.xsd"
book genre="autobiography" publicationdate="1981"
ISBN="1-861003-11-0"
title>The Autobiography of Benjamin Franklin</title
author
first-name>Benjamin</first-name
last-name>Franklin</last-name
/author
price></price
/book
book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"
title>The Confidence Man</title
author
first-name>Herman</first-name
last-name>Melville</last-name
/author
price>11.99</price
/book
book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"
title>The Gorgias</title
author
first-name>Sidas</first-name
last-name>Plato</last-name
/author
price>9.99</price
/book
/bookstore

when I did the validation, gave me a error saying that
Validation error: The 'schema.xsdrice' element has an invalid
value according to its data type.

I know it is because there is a empty element
price></price
in my xml file.
if there any solution to use so that the xml XmlValidatingReader can
recognize the null value?

Thanks.

Lynn










Reply With Quote
  #4  
Old   
Zafar Abbas [MSFT]
 
Posts: n/a

Default Re: null value in XML - 08-16-2004 , 03:57 PM



It coudn't because then it will try to validate an empty value against the
data type xs:decimal, it will throw a validation error. If you want to
validate empty value for the price element, them you should have it typed as
xs:string and then put pattern restrictions on ONLY accept numbers and an
empty value.

HTH,
Zafar

"Lynn" <xiao_lin_zeng (AT) hotmail (DOT) com> wrote

Quote:
Thanks Zafar.
That works.
Is that possible that it can work without
xsi:nil attribute?

thanks.

Lynn


"Zafar Abbas [MSFT]" <zafara (AT) microsoft (DOT) com> wrote in message
news:%238Dlr47gEHA.632 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
In the schema put the nillable true attribute on the price element like:

xsd:element name="price" type="xsd:decimal" nillable="true"/

and in the XML set the xsi:nil=true but you have to map the xsi
namespace
first. Your new XML is:

bookstore xmlns = "schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
book genre="autobiography" publicationdate="1981"
ISBN="1-861003-11-0"
title>The Autobiography of Benjamin Franklin</title
author
first-name>Benjamin</first-name
last-name>Franklin</last-name
/author
price xsi:nil="true"></price
/book
book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"
title>The Confidence Man</title
author
first-name>Herman</first-name
last-name>Melville</last-name
/author
price>11.99</price
/book
book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6"
title>The Gorgias</title
author
first-name>Sidas</first-name
last-name>Plato</last-name
/author
price>9.99</price
/book
/bookstore


"Lynn" <xiao_lin_zeng (AT) hotmail (DOT) com> wrote in message
news:uWfD8W7gEHA.3476 (AT) tk2msftngp13 (DOT) phx.gbl...
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"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop"
elementFormDefault="qualified" targetNamespace="schema.xsd"
xsd:element name="bookstore" type="bookstoreType" /
xsd:complexType name="bookstoreType"
xsd:sequence maxOccurs="unbounded"
xsd:element name="book" type="bookType" /
/xsd:sequence
/xsd:complexType
xsd:complexType name="bookType"
xsd:sequence
xsd:element name="title" type="xsd:string" /
xsd:element name="author" type="authorName" /
xsd:element name="price" type="xsd:decimal" /
/xsd:sequence
xsd:attribute name="genre" type="xsd:string" /
xsd:attribute name="publicationdate" type="xsd:string" /
xsd:attribute name="ISBN" type="xsd:string" /
/xsd:complexType
xsd:complexType name="authorName"
xsd:sequence
xsd:element name="first-name" type="xsd:string" /
xsd:element name="last-name" type="xsd:string" /
/xsd:sequence
/xsd:complexType
/xsd:schema

and the xml file is:
?xml version='1.0'?
!-- This file represents a fragment of a book store inventory
database --
bookstore xmlns = "schema.xsd"
book genre="autobiography" publicationdate="1981"
ISBN="1-861003-11-0"
title>The Autobiography of Benjamin Franklin</title
author
first-name>Benjamin</first-name
last-name>Franklin</last-name
/author
price></price
/book
book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"
title>The Confidence Man</title
author
first-name>Herman</first-name
last-name>Melville</last-name
/author
price>11.99</price
/book
book genre="philosophy" publicationdate="1991"
ISBN="1-861001-57-6"
title>The Gorgias</title
author
first-name>Sidas</first-name
last-name>Plato</last-name
/author
price>9.99</price
/book
/bookstore

when I did the validation, gave me a error saying that
Validation error: The 'schema.xsdrice' element has an
invalid
value according to its data type.

I know it is because there is a empty element
price></price
in my xml file.
if there any solution to use so that the xml XmlValidatingReader can
recognize the null value?

Thanks.

Lynn












Reply With Quote
  #5  
Old   
sirajbg
 
Posts: n/a

Default Re: null value in XML - 11-22-2007 , 04:13 AM




Hi Zafar,All
I am also facing null value problem.can you suggest me a solution.
in my wsdl file i have

<xsd:simpleType name="VehicleType" >
<xsd:annotation>
<xsd:documentation>Defines the available vehicle
types</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="sedan"/>
<xsd:enumeration value="suv"/>
<xsd:enumeration value="van"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="Reservation">
<xsd:element maxOccurs="1" minOccurs="0" name="vehicleType"
type="xsd1:VehicleType" nillable="true"/>
</xsd:complexType>

And in my ws-application.xml file:

<mapping>
<schemaType>VehicleType</schemaType>
<javaType>....model.VehicleType</javaType>
<holder>....model.VehicleTypeHolder</holder>
</mapping>

I have placed nillble="true" in wsdl file.
But where can i place xsi:nil="true".
How can i give null.

Awaiting for your reply

siraj.


--
sirajbg

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.