2016-01-29 73 views
1

我正在錯誤「找不到元素soapenv聲明:信封」得到錯誤找不到元素的聲明「soapenv:信封」

做工精細與其他XML文件xsd..Issue與以下那些..

我的XML文件是: -

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ 
    http://schemas.xmlsoap.org/soap/envelope/ 
    /tmp/checkxsd.xsd"> 
    <soapenv:Body> 
    <ns:getEntitiesByFilterResponse 
    xmlns:ns="http://services" 
    xmlns:ax21="http://objects.services/xsd"> 
    <ns:return xsi:type="ax21:EntityObj"> 
     <ax21:entityId>1065798192</ax21:entityId> 
     <ax21:entityTypeId>4</ax21:entityTypeId> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>Project SoapUI 001</ax21:elementValue> 
      <ax21:id>436</ax21:id> 
     </ax21:methodValues> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>Project SoapUI 001</ax21:elementValue> 
      <ax21:id>100461</ax21:id> 
     </ax21:methodValues> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>Project SoapUI 001</ax21:elementValue> 
      <ax21:id>400015</ax21:id> 
     </ax21:methodValues> 
    </ns:return> 
    <ns:return xsi:type="ax21:EntityObj"> 
     <ax21:entityId>1065835163</ax21:entityId> 
     <ax21:entityTypeId>4</ax21:entityTypeId> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>Project SoapUI 002</ax21:elementValue> 
      <ax21:id>436</ax21:id> 
     </ax21:methodValues> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>Project SoapUI 002</ax21:elementValue> 
      <ax21:id>100461</ax21:id> 
     </ax21:methodValues> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>Project SoapUI 002</ax21:elementValue> 
      <ax21:id>400015</ax21:id> 
     </ax21:methodValues> 
    </ns:return> 
    <ns:return xsi:type="ax21:EntityObj"> 
     <ax21:entityId>1317237376</ax21:entityId> 
     <ax21:entityTypeId>4</ax21:entityTypeId> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue> 
      <ax21:id>436</ax21:id> 
     </ax21:methodValues> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue> 
      <ax21:id>100461</ax21:id> 
     </ax21:methodValues> 
     <ax21:methodValues xsi:type="ax21:ValuePair"> 
      <ax21:elementValue>CopyTask_project_1448004605927</ax21:elementValue> 
      <ax21:id>400015</ax21:id> 
     </ax21:methodValues> 
    </ns:return> 
    </ns:getEntitiesByFilterResponse></soapenv:Body></soapenv:Envelope> 

請在下面查找XSD: -

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://objects.services/xsd"> 
    <xs:element name="entityId"> 
     <xs:simpleType> 
     <xs:restriction base="xs:int"> 
      <xs:enumeration value="1065798192" /> 
      <xs:enumeration value="1065835163" /> 
      <xs:enumeration value="1317237376" /> 
     </xs:restriction> 
     </xs:simpleType> 
    </xs:element> 
    <xs:element name="entityTypeId" type="xs:byte" /> 
    <xs:element name="methodValues"> 
     <xs:complexType> 
     <xs:sequence> 
      <xs:element name="elementValue"> 
       <xs:simpleType> 
        <xs:restriction base="xs:string"> 
        <xs:enumeration value="Project SoapUI 001" /> 
        <xs:enumeration value="Project SoapUI 002" /> 
        <xs:enumeration value="CopyTask_project_1448004605927" /> 
        </xs:restriction> 
       </xs:simpleType> 
      </xs:element> 
      <xs:element name="id"> 
       <xs:simpleType> 
        <xs:restriction base="xs:int"> 
        <xs:enumeration value="436" /> 
        <xs:enumeration value="100461" /> 
        <xs:enumeration value="400015" /> 
        </xs:restriction> 
       </xs:simpleType> 
      </xs:element> 
     </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

我的Java代碼來驗證XSD對XML如下: -

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
    Schema schema = factory.newSchema(new File("/tmp/checkxsd.xsd")); 
    Validator validator = schema.newValidator(); 
    validator.validate(new StreamSource(new File("/home/my-pc/MyXMLFile.xml")) 

任何幫助是極大的讚賞。我堅持這一點。

回答

1

您看到的消息幾乎總是意味着驗證程序未加載模式;反過來,這幾乎總是因爲它找不到;這反過來幾乎總是因爲在指定要處理的模式文檔的位置時出錯。

一旦您的示例中的超長行被破壞,並且可以方便地讀取最外層元素的開始標記而無需左右滾動,您的問題的一個來源(不一定是唯一的一個)似乎很清楚。你相信什麼是屬性值規範

xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ 
        http://schemas.xmlsoap.org/soap/envelope/ 
        /tmp/checkxsd.xsd"> 

的意義(在這一點上,我希望你要麼有頭巴掌經驗或提高你的眉毛困惑。如果是後者,我建議你諮詢一些文檔)。

+0

謝謝朋友.. :) – Java4ever

相關問題