Cvc-elt.1: Cannot Find The Declaration Of Element 'soap:Envelope'

10,014

First, you must add a targetNamespace="http://tempuri.org/" to the xs:schema element of your XSD in order for your XSD to apply to the namespace used in your XML payload.

Then you can take either of the following approaches: Change the XML or Change the XSD. Choose according to which files you control.

Change the XML

Add

xsi:schemaLocation="http://tempuri.org/ tempuri.xsd
                    http://schemas.xmlsoap.org/soap/envelope/ 
                    http://schemas.xmlsoap.org/soap/envelope/

to the soap:Envelope:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xsi:schemaLocation="http://tempuri.org/ tempuri.xsd
                                   http://schemas.xmlsoap.org/soap/envelope/ 
                                   http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Cancel_OrderLine xmlns="http://tempuri.org/">
      <Data>
        <Delivery>
          <Delivery_No>1605000194</Delivery_No>
          <Reason>qwertyu</Reason>
        </Delivery>
        <Delivery>
          <Delivery_No>1605000194</Delivery_No>
          <Reason>qwerty</Reason>
        </Delivery>
      </Data>
    </Cancel_OrderLine>
  </soap:Body>
</soap:Envelope>

Change the XSD

Add

<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"   
           schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>

to the xs:schema element of your XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
           targetNamespace="http://tempuri.org/">

  <xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"   
             schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>

  <xs:element name="Cancel_OrderLineReq">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Data">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Delivery" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:int" name="Delivery_No"/>
                    <xs:element type="xs:string" name="Reason"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Both methods will allow successful validation of your SOAP envelop and its payload.

Share:
10,014
chyman-91
Author by

chyman-91

Updated on July 04, 2022

Comments

  • chyman-91
    chyman-91 almost 2 years

    Currently I'm using XSD for SOAP XML, but when I run my SOAP XML and XSD on FREEFORMATTER.COM, I get this error:

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

    This is my SOAP XML:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <Cancel_OrderLine xmlns="http://tempuri.org/">
          <Data>
            <Delivery>
              <Delivery_No>1605000194</Delivery_No>
              <Reason>qwertyu</Reason>
            </Delivery>
            <Delivery>
              <Delivery_No>1605000194</Delivery_No>
              <Reason>qwerty</Reason>
            </Delivery>
          </Data>
        </Cancel_OrderLine>
      </soap:Body>
    </soap:Envelope>
    

    This is my XSD:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <xs:element name="Cancel_OrderLineReq">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Data">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Delivery" maxOccurs="unbounded" minOccurs="0">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element type="xs:int" name="Delivery_No"/>
                        <xs:element type="xs:string" name="Reason"/>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
    

    What should I do to eliminate the error?

  • chyman-91
    chyman-91 over 7 years
    hello, thakz it work on the freeformatter.com/xml-validator-xsd.html but when i implement in my ColdFusion test page, it give me to same result
  • kjhughes
    kjhughes over 7 years
    You didn't say which of the two methods you tried. Keep in mind that changing only the XSD still requires some way for you to associate the XML with the XSD; whereas adding xsi:schemaLocation to the XML provides a hint to the parser as to where to find the XSD.
  • chyman-91
    chyman-91 over 7 years
    Hello, both method i had tried it. Both also work in the freeformatter.com/xml-validator-xsd.html website. But not in my coldfusion test page. first, I assigned the xml into a variable in my test page b4 based it to the xsd.
  • kjhughes
    kjhughes over 7 years
    Both methods are correct from an XML and XSD perspective. Whatever trouble you're having can only be related to how you're validating in Coldfusion. I'd suggest that you ask a new question for that, being sure to show your code and specify the version of CF and any libraries involved.