我收到一条错误,指出''不是'整数'的有效值。我尝试使用 nillable =“true”作为元素并尝试更改使用限制的模式值。 xml文件中的 parentInstanceId 元素没有任何值。但是我应该给它一个20个字符的限制。
这是我的xsd文件。
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="createSalesOrder"> <!--root-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="order"> <!--sub-root-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="orderSource"> <!--orderSource-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="purchaseOrder"> <!--purchaseOrder-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="purchaseOrderType"> <!--purchaseOrderType-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="purchaseOrderDate"> <!--purchaseOrderDate-->
<xs:simpleType>
<xs:restriction base="xs:date"/>
</xs:simpleType>
</xs:element>
<xs:element name="orderType"> <!--orderType-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="orderExpiry"> <!--orderExpiry-->
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="orderConsumerReferenceId"> <!--OCRId-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="orderSourceReferenceId"> <!--OSRId-->
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="\d{7}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="shipping"> <!--shipping-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="requestedDate" type="xs:dateTime"/>
<xs:element name="shipmentOrigin" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="orderCurrency"> <!--orderCurrency-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="currencyCode" type="xs:string" default="EUR"/>
<xs:element name="currencyExchangeRate">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:enumeration value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="partner" maxOccurs="unbounded"> <!--partner-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="partnerRole" type="xs:string"/>
<xs:element name="partnerId"/>
<xs:element name="communicationLanguageCode" type="xs:string"/>
<xs:element name="address" minOccurs="0" maxOccurs="unbounded">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="value">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="salesOrganization"> <!-- salesOrganization -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="distributionChannel"> <!--distributionChannel-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="division" type="xs:integer"/>
<xs:element name="orderTerm" minOccurs="1" maxOccurs="unbounded"> <!--orderTerm-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="value">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="2 YEARS"/>
<xs:enumeration value="3 YEARS"/>
<xs:enumeration value="4 YEARS"/>
<xs:enumeration value="5 YEARS"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lineItem" minOccurs="0"> <!--lineItem-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="lineId" type="xs:integer"/>
<xs:element name="parentLineId"> <!--parentId-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="12"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="materialFlowType" type="xs:integer"/>
<xs:element name="material" minOccurs="1" type="xs:string"/>
<xs:element name="materialDescription" minOccurs="0"> <!--materialDescription-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="orderedQuantity" minOccurs="1" type="xs:integer"/>
<xs:element name="configuration"> <!--configuration-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="instanceId"> <!--instanceId-->
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="\d{1,20}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="parentInstanceId" nillable="false"> <!--parentInstanceId-->
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{0,20}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="quantity" type="xs:integer"/>
<xs:element name="objectKey"> <!--objectKey-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="25"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="characteristics" maxOccurs="unbounded"> <!--characteristics-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="type" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="value" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element> <!--characteristics ends-->
</xs:sequence>
</xs:complexType>
</xs:element> <!--configuration ends-->
<xs:element name="price"> <!--price-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name"> <!--name-->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="value" type="xs:decimal"/>
<xs:element name="currencyCode" default="EUR" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element> <!--price ends-->
<xs:element name="shippingDate"> <!--shippingDate-->
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="value" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:element> <!--shippingDate ends-->
<xs:element name="shipmentOrigin" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element> <!--lineItem ends-->
<xs:element name="callbackUrl" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这是我应该为其开发xsd文件的xml文件
<createSalesOrder>
(M)
<order>
(M)
<orderSource>BridgeSAP</orderSource>
//restriction of 30 characters (M)
<purchaseOrder>test USO now</purchaseOrder>
//restriction of 20 characters (M)
<purchaseOrderType>ZSATA</purchaseOrderType>
//restriction of 5 characters, refer from value (M)
<purchaseOrderDate>2015-06-25</purchaseOrderDate>
//restriction as of the value (M)
<orderType>ZOR</orderType>
//restriction of 10 characters (O)
<orderExpiry>2</orderExpiry>
//restriction of expiry ranges from 1-5
<orderConsumerReferenceId>order017</orderConsumerReferenceId>
//restriction of 20 characters (M)
<orderSourceReferenceId>6003670</orderSourceReferenceId>
//restriction of 8 numbers (M)
<shipping>
<requestedDate>2015-10-30T15:12:25</requestedDate>
//restriction as of the value (M)
<shipmentOrigin>true</shipmentOrigin>
//restriction as of the value (O)
</shipping>
<orderCurrency>
<currencyCode>EUR</currencyCode>
//default the currency to EUR and provide restrictions (M)
<currencyExchangeRate>1</currencyExchangeRate>
//restriction as of the value (M)
</orderCurrency>
<partner>
<partnerRole>AG</partnerRole>
//restriction as of the value (M)
<partnerId>CFR01440</partnerId>
//restriction as of the value (M)
<communicationLanguageCode>fr</communicationLanguageCode>
//restriction as of the value (O)
</partner>
<partner>
<partnerRole>WE</partnerRole>
<partnerId/>
<communicationLanguageCode>ag</communicationLanguageCode>
<address>
(O)
<name>NAME1</name>
//restriction of 10 characters (M)
<value>Example Name 1</value>
//restriction of 50 characters (O)
</address>
<address>
<name>NAME2</name>
<value>Example Name 2</value>
</address>
</partner>
<salesOrganization>FR08</salesOrganization>
//restriction of 10 characters (M)
<distributionChannel>IG</distributionChannel>
//restriction as of the value (M)
<division>01</division>
//restriction as of the value (M)
<orderTerm>
(M)
<name>INCO1</name>
//restriction as of the value (M)
<value>2 YEARS</value>
//restriction as of enumeration (2 YEARS, 3 YEARS, 4 YEARS, 5 YEARS) (M)
</orderTerm>
<orderTerm>
<name>INCO2</name>
<value>3 YEARS</value>
</orderTerm>
<orderTerm>
<name>ZTERM</name>
<value>4 YEARS</value>
</orderTerm>
<lineItem>
(O)
<lineId>1000</lineId>
//restriction as of the value (M)
<parentLineId/>
//restriction of 12 characters (O)
<materialFlowType>1</materialFlowType>
//restriction as of the value (M)
<material>GCR_S24SWB_01</material>
//restriction as of the value (M)
<materialDescription>SM6 24kV</materialDescription>
//restriction of 20 characters (O)
<orderedQuantity>1</orderedQuantity>
//restriction as of the value (M)
<configuration>
<instanceId>00000001</instanceId>
//restriction as of 20 characters (M)
<parentInstanceId/>
//restriction as of 20 characters (O)
<quantity>1</quantity>
//restriction as of the value (M)
<objectKey>GCR_S24SWB_01</objectKey>
//restriction as of 25 characters (M)
<characteristics>
<type>PRO_ARKTX1</type>
//restriction as of 15 characters (M)
<value>SM6 Test</value>
//restriction as of 20 characters (M)
</characteristics>
<characteristics>
<type>PRO_ETO_FLAG</type>
<value>1</value>
</characteristics>
</configuration>
<price>
<name>ZPN0</name>
//restriction as of 15 characters (M)
<value>4500.50</value>
//restriction as of the value (M)
<currencyCode>EUR</currencyCode>
//default the currency to EUR and provide restrictions (M)
</price>
<shippingDate>
<name>ETDAT</name>
//restriction as of 15 characters (M)
<value>2015-10-30T15:12:25</value>
//restriction as of the value (M)
</shippingDate>
<shipmentOrigin>FR12</shipmentOrigin>
//restriction as of the value (O)
</lineItem>
<callbackUrl>https://www.example.com/xml</callbackUrl>
</order>
</createSalesOrder>
答案 0 :(得分:2)
在XML文档中,您需要<parentInstanceId xsi:nil="true"/>
表示没有值,请参阅https://www.w3.org/TR/xmlschema-0/#Nils以获取完整示例。
答案 1 :(得分:2)
有两种方法可以定义一个接受整数或零接口的simpleType(零长度字符串):
(a)定义一个具有两个成员类型的联合类型,一个是xs:integer(或其子类型),另一个是xs:string的限制,长度为&#34; 0&#34;。
(b)定义一个列表类型,项目类型为xs:integer,maxLength =&#34; 1&#34;。
就验证XML而言,这两种方法是等效的,但它们可能与数据绑定技术或模式感知XSLT和XQuery的行为不同。