Error: Validating XML against XSD in JDev 11g

南楼画角 提交于 2019-12-25 05:36:16

问题


I am using JDEV11.1.1.7.0. I am a newbie to Webservices and SOAP. I am building a Web Service from an Existing WSDL.

i.e. I create an XSD and WSDL and then creating a Web Service over it. I am able to test the web service. I am getting the output as required. But, when i validate the XML against the XSD, it has an error.

The XSD is prepared by referring to a very popular blog http://one-size-doesnt-fit-all.blogspot.in/2008/11/creating-jax-ws-web-services-via-wsdl.html

Request XML taken from HTTP Analyzer:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" 
              xmlns:ns1="http://www.sagecomputing.com.au">  
   <env:Header/>  
   <env:Body>  
      <ns1:formInput>  
         <ns1:inputField1>1</ns1:inputField1>  
         <ns1:inputField2>Morning</ns1:inputField2>  
      </ns1:formInput>  
   </env:Body>  
</env:Envelope> 

Response XML taken from HTTP Analyzer:

<?xml version = '1.0' encoding = 'UTF-8'?>  
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">  
   <S:Body>  
      <formOutput xmlns="http://www.sagecomputing.com.au">  
         <outputField1>6</outputField1>  
         <outputField2>Morning: Welcome!</outputField2>  
         <outputField3>This is your reply</outputField3>  
      </formOutput>  
   </S:Body>  
</S:Envelope>

XSD:

<?xml version="1.0" encoding="windows-1252" ?>  
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
  targetNamespace="http://www.sagecomputing.com.au"  
  elementFormDefault="qualified">  
  <xsd:element name="formInput">  
    <xsd:complexType>  
      <xsd:sequence>  
        <xsd:element name="inputField1" type="xsd:integer"/>  
      <xsd:element name="inputField2" type="xsd:string"/>  
      </xsd:sequence>  
    </xsd:complexType>  
  </xsd:element>  
  <xsd:element name="formOutput">  
    <xsd:complexType>  
      <xsd:sequence>  
        <xsd:element name="outputField1" type="xsd:integer"/>  
        <xsd:element name="outputField2" type="xsd:string"/>  
        <xsd:element name="outputField3" type="xsd:string"/>  
      </xsd:sequence>  
    </xsd:complexType>  
  </xsd:element>  
</xsd:schema>

When the XML is validated against the XSD, I get the below error.

Cvc-elt.1: Cannot Find The Declaration Of Element 'S:Envelope'.. Line '1', Column '63'

I compared using Free Online XML Validator Against XSD Schema - http://www.freeformatter.com/xml-validator-xsd.html

Can someone please tell me, what is the mistake I am doing?

Is there any imports that I am missing?


回答1:


Try to use the following xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
targetNamespace="http://www.sagecomputing.com.au"  
elementFormDefault="qualified">  
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" 
    schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
<xsd:element name="formInput">  
    <xsd:complexType>  
        <xsd:sequence>  
            <xsd:element name="inputField1" type="xsd:integer"/>  
            <xsd:element name="inputField2" type="xsd:string"/>  
        </xsd:sequence>  
    </xsd:complexType>  
</xsd:element>  
<xsd:element name="formOutput">  
    <xsd:complexType>  
        <xsd:sequence>  
            <xsd:element name="outputField1" type="xsd:integer"/>  
            <xsd:element name="outputField2" type="xsd:string"/>  
            <xsd:element name="outputField3" type="xsd:string"/>  
        </xsd:sequence>  
    </xsd:complexType>  
</xsd:element>  

Update:

validate your SOAP Request Message against the above xsd:

 <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.sagecomputing.com.au"
        xsi:schemaLocation="http://www.sagecomputing.com.au soapMessage.xsd">
        <Header/>
        <Body>
            <ns1:formInput>  
                <ns1:inputField1>1</ns1:inputField1>  
                <ns1:inputField2>Morning</ns1:inputField2>  
            </ns1:formInput> 

        </Body>
    </Envelope>

validate your SOAP Response Message against the above xsd:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sagecomputing.com.au soapMessage.xsd">
<Header/>
<Body>
    <formOutput xmlns="http://www.sagecomputing.com.au">  
        <outputField1>6</outputField1>  
        <outputField2>Morning: Welcome!</outputField2>  
        <outputField3>This is your reply</outputField3>  
    </formOutput>  
</Body>
</Envelope>


来源:https://stackoverflow.com/questions/31667727/error-validating-xml-against-xsd-in-jdev-11g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!