![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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.xsd rice' element has an invalidvalue 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 |
#3
| |||
| |||
|
|
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.xsd rice' element has an invalidvalue 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 |
#4
| |||
| |||
|
|
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.xsd rice' element has aninvalid 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 |
#5
| |||
| |||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |