Not enough values specified for <unique> identity constraint specified for element "Declaration".
在进行XML校验出现上面的提示,有人遇到过吗?

解决方案 »

  1.   

    是不是需要有一个名为Declaration的节点,而你的xml中没有
      

  2.   


    这是XML的文件
    <?xml version="1.0" encoding="UTF-8"?><Manifest xmlns="urn:Declaration:datamodel:standard:CN:MT2101:1" >
      <Head> 
        <MessageID>CN_MT2101_1p0_COS001000120100627010905235</MessageID>  
        <FunctionCode>9</FunctionCode>  
        <MessageType>MT2101</MessageType>  
        <SenderID>4200718022890</SenderID>  
        <ReceiverID>CNCustoms</ReceiverID>  
        <SendTime>20100627010905235</SendTime>  
        <Version>1.0</Version> 
      </Head>  
      <Declaration> 
        <RepresentativePerson> 
          <Name>4200718022890</Name> 
        </RepresentativePerson>  
        <ExitCustomsOffice> 
          <ID>4218</ID> 
        </ExitCustomsOffice>  
        <Agent> 
          <ID>4200718022890</ID> 
        </Agent>  
        <Carrier>
          <ID>PANASIA</ID> 
        </Carrier>
        <BorderTransportMeans> 
          <JourneyID>070E</JourneyID>  
          <TypeCode>1</TypeCode>  
          <ID>9200718</ID>  
          <Name>HANJIN OTTAWA</Name> 
        </BorderTransportMeans>  
        <Consignment> 
          <TransportContractDocument> 
            <ID>PASU5108235587</ID>  
            <ConditionCode>10</ConditionCode> 
          </TransportContractDocument>  
          <LoadingLocation> 
            <ID>CNYTA/4201</ID> 
            <LoadingDate>201006182300086</LoadingDate>
          </LoadingLocation>  
          <UnloadingLocation> 
            <ID>JPOSA</ID> 
          </UnloadingLocation>  
          <GoodsReceiptPlace> 
            <ID>JPOSA</ID>  
            <Name>OSAKA</Name> 
          </GoodsReceiptPlace>  
          <CustomsStatusCode>001</CustomsStatusCode> 
          <FreightPayment> 
            <MethodCode>PP</MethodCode> 
          </FreightPayment>  
          <ConsignmentPackaging> 
            <QuantityQuantity>39</QuantityQuantity>  
            <TypeCode>CT</TypeCode> 
          </ConsignmentPackaging>  
          <TotalGrossMassMeasure>390.0</TotalGrossMassMeasure>  
          <Consignee> 
            <Name>COSCO CONTAINER LINES</Name>  
            <Address>
              <Line>iwatani corporation 21-8,nishi-simbashi 3-chome minato-ku tokyo 105 ja</Line> 
            </Address>
          </Consignee>  
          <Consignor> 
            <Name>COSCO CONTAINER LINES</Name>  
            <Address>
              <Line>iwatani corporation 21-8,nishi-simbashi 3-chome minato-ku tokyo 105 ja</Line> 
            </Address>
          </Consignor>  
          <NotifyParty> 
            <Name>COSCO CONTAINER LINES</Name>  
            <Address>
              <Line>iwatani corporation 21-8,nishi-simbashi 3-chome minato-ku tokyo 105 ja</Line> 
            </Address>
          </NotifyParty>  
          <TransportEquipment> 
            <EquipmentIdentification> 
              <ID>CBHU5882789</ID> 
            </EquipmentIdentification>  
            <CharacteristicCode>20GP</CharacteristicCode>  
            <FullnessCode>7</FullnessCode>  
            <SealID AgencyCode="SH">X74787</SealID> 
          </TransportEquipment>  
          <ConsignmentItem> 
            <SequenceNumeric>1</SequenceNumeric>  
            <ConsignmentItemPackaging> 
              <QuantityQuantity>39</QuantityQuantity>  
              <TypeCode>CT</TypeCode>  
              <MarksNumbers>N/M</MarksNumbers> 
            </ConsignmentItemPackaging>  
            <Commodity> 
              <CargoDescription>LADY'S WEAR</CargoDescription> 
            </Commodity>  
            <GoodsMeasure> 
              <GrossMassMeasure>390.0</GrossMassMeasure> 
            </GoodsMeasure> 
          </ConsignmentItem> 
        </Consignment>  
      </Declaration> 
    </Manifest>
      

  3.   

    这个XSD头文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSpy v2008 (http://www.altova.com) by lei_ying (szc) -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:decl="urn:Declaration:datamodel:standard:CN:MT2101:1" xmlns:Head="Head" xmlns:Declaration="Declaration" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:Message="Message" targetNamespace="urn:Declaration:datamodel:standard:CN:MT2101:1" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:import namespace="Head" schemaLocation="Type/HeadDefine.xsd"/>
    <xs:import namespace="Declaration" schemaLocation="Type/DeclarationDefine.xsd"/>
    <xs:import namespace="Message" schemaLocation="Type/MessageDefine.xsd"/>
    <xs:element name="Manifest" type="decl:Manifest">
    <xs:annotation>
    <xs:documentation>海运预配舱单主要数据申报</xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:complexType name="Manifest">
    <xs:annotation>
    <xs:documentation>海运预配舱单主要数据申报</xs:documentation>
    </xs:annotation>
    <xs:sequence>
    <xs:element name="Head" type="decl:Head">
    <xs:annotation>
    <xs:documentation>报文头</xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:element name="Declaration">
    <xs:annotation>
    <xs:documentation>报文体</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:complexContent>
    <xs:extension base="decl:Declaration"/>
    </xs:complexContent>
    </xs:complexType>
    <xs:unique name="DeclarationUnique">
    <xs:annotation>
    <xs:documentation>约束:总提运单+分提运单在同一份报文中不重复</xs:documentation>
    </xs:annotation>
    <xs:selector xpath="decl:Consignment"/>
    <xs:field xpath="decl:AssociatedTransportDocument/decl:ID"/>
    <xs:field xpath="decl:TransportContractDocument/decl:ID"/>
    </xs:unique>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
      

  4.   

    应该是Declaration少DeclarationUnique节点吧
    你可以用xmlspy把xsd文件生成一个样例,对比一下就知道了
      

  5.   

    哥们,同样的文件,用XMLSpy校验就没问题,但java中校验就会出现这个提示
      

  6.   


    可能是xerces版本的问题。
      

  7.   


    如你所说,确实是他的问题,定义文件中有以下下内容
    <xs:unique name="DeclarationUnique">
    <xs:annotation>
    <xs:documentation>约束:总提运单+分提运单在同一份报文中不重复</xs:documentation>
    </xs:annotation>
    <xs:selector xpath="decl:Consignment"/>
    <xs:field xpath="decl:AssociatedTransportDocument/decl:ID"/>
    <xs:field xpath="decl:TransportContractDocument/decl:ID"/>
    </xs:unique>
    </xs:element>把<xs:field xpath="decl:AssociatedTransportDocument/decl:ID"/>这段内容去掉
    就OK了