xsd浮点数和带空值的日期

时间:2015-03-30 13:37:09

标签: xml xsd

嗨,以下是我的xml

<?xml version="1.0" encoding="UTF-8"?>
<CatalogObjects loadItemName="CatalogEntryOfferPrice">
<Catalog>
<PriceListUniqueId></PriceListUniqueId>
<PriceListName>MadisonsNominal Products Price List</PriceListName>
<CatentryUniqueId></CatentryUniqueId>
<CatentryPartNumber>012-300-050-RX</CatentryPartNumber>
<Identifier></Identifier>
<Precedence>0</Precedence>
<StartDate></StartDate>
<EndDate></EndDate>
<QuantityUnitIdentifier></QuantityUnitIdentifier>
<MinimumQuantity></MinimumQuantity>
<MaximumQuantity></MaximumQuantity>
<LastUpdate></LastUpdate>
<Description></Description>
<PriceInUSD>45</PriceInUSD>
<PriceInBRL></PriceInBRL>
<PriceInCAD></PriceInCAD>
<PriceInCNY></PriceInCNY>
<PriceInEUR></PriceInEUR>
<PriceInJPY></PriceInJPY>
<PriceInKRW></PriceInKRW>
<PriceInTWD></PriceInTWD>
<Delete>0</Delete>
</Catalog>

为此我创建了xsd,如下所示

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified">
 <xs:element name="CatalogObjects">
  <xs:complexType>
<xs:sequence>
<xs:element ref="Catalog" />
</xs:sequence>
<xs:attribute type="xs:string" name="loadItemName" fixed="CatalogEntryOfferPrice" use="required"/>
  </xs:complexType>
</xs:element>
<xs:element name="Catalog" >
 <xs:complexType>
<xs:sequence>
       <xs:element type="xs:string" name="PriceListUniqueId" />
       <xs:element type="xs:string" name="PriceListName" />
       <xs:element type="xs:string" name="CatentryUniqueId" />
       <xs:element type="xs:string" name="CatentryPartNumber" />
       <xs:element type="xs:string" name="Identifier" />
       <xs:element type="xs:byte" name="Precedence" />
       <xs:element type="xs:string" name="StartDate" />
       <xs:element type="xs:string" name="EndDate" />
       <xs:element type="xs:string" name="QuantityUnitIdentifier" />
       <xs:element type="xs:string" name="MinimumQuantity" />
       <xs:element type="xs:string" name="MaximumQuantity" />
       <xs:element type="xs:string" name="LastUpdate" />
       <xs:element type="xs:string" name="Description" />
       <xs:element type="xs:float" name="PriceInUSD" />
       <xs:element type="xs:float" name="PriceInBRL" />
       <xs:element type="xs:float" name="PriceInCAD" />
       <xs:element type="xs:float" name="PriceInCNY" />
       <xs:element type="xs:float" name="PriceInEUR" />
       <xs:element type="xs:float" name="PriceInJPY" />
       <xs:element type="xs:float" name="PriceInKRW" />
       <xs:element type="xs:float" name="PriceInTWD" />
       <xs:element type="xs:byte" name="Delete" fixed="0"/>
    </xs:sequence>
   </xs:complexType>
 </xs:element>
 </xs:schema>  

我想要价格元素和日期元素可以为空但我收到“日期”和“浮动”元素的错误如下所示

Error - Line 10, 25: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 25; cvc-datatype-valid.1.2.1: '' is not a valid value for 'date'.
Error - Line 10, 25: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 25; cvc-type.3.1.3: The value '' of element 'StartDate' is not valid.
Error - Line 11, 21: org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 21; cvc-datatype-valid.1.2.1: '' is not a valid value for 'date'.
Error - Line 11, 21: org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 21; cvc-type.3.1.3: The value '' of element 'EndDate' is not valid.
Error - Line 18, 27: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 27; cvc-datatype-valid.1.2.1: '' is not a valid value for 'float'.
Error - Line 18, 27: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 27; cvc-type.3.1.3: The value '' of element 'PriceInBRL' is not valid.
Error - Line 19, 27: org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 27; cvc-datatype-valid.1.2.1: '' is not a valid value for 'float'.
Error - Line 19, 27: org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 27; cvc-type.3.1.3: The value '' of element 'PriceInCAD' is not valid.
Error - Line 20, 27: org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 27; cvc-datatype-valid.1.2.1: '' is not a valid value for 'float'.
Error - Line 20, 27: org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 27; cvc-type.3.1.3: The value '' of element 'PriceInCNY' is not valid.
Error - Line 21, 27: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 27; cvc-datatype-valid.1.2.1: '' is not a valid value for 'float'.
Error - Line 21, 27: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 27; cvc-type.3.1.3: The value '' of element 'PriceInEUR' is not valid.
Error - Line 22, 27: org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 27; cvc-datatype-valid.1.2.1: '' is not a valid value for 'float'.
Error - Line 22, 27: org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 27; cvc-type.3.1.3: The value '' of element 'PriceInJPY' is not valid.
Error - Line 23, 27: org.xml.sax.SAXParseException; lineNumber: 23; columnNumber: 27; cvc-datatype-valid.1.2.1: '' is not a valid value for 'float'.
Error - Line 23, 27: org.xml.sax.SAXParseException; lineNumber: 23; columnNumber: 27; cvc-type.3.1.3: The value '' of element 'PriceInKRW' is not valid.
Error - Line 24, 27: org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 27; cvc-datatype-valid.1.2.1: '' is not a valid value for 'float'.
Error - Line 24, 27: org.xml.sax.SAXParseException; lineNumber: 24; columnNumber: 27; cvc-type.3.1.3: The value '' of element 'PriceInTWD' is not valid.

我试过xsd nullable,minOccurs和maxOccurs但我没有成功。任何人都可以对minOccurs,maxOccurs和xsd可以解决这个问题吗?祝谢

1 个答案:

答案 0 :(得分:1)

将nillability设置为true会导致如果空元素带有属性值规范xsi:nil="true"(或等效项 - 名称空间前缀可能不同,并且值可能是文字{{},则允许使用空元素。 1}}而不是1)。但true的默认值为false。

如果要在不指定xsi:nil的情况下允许该值不存在,一种方法是定义第一个成员为xsd:float(或xsd:date)且第二个成员为限制的联合类型of xsd:string,其单个值为空字符串。