问题
I want to check a soap response against a xsd. Here is the xml soap response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetHTMLResponse xmlns="http://www.webserviceX.NET">
<GetHTMLResult>
Test
</GetHTMLResult>
</GetHTMLResponse>
</soap:Body>
</soap:Envelope>
Here is my XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
<xs:element name="GetHTMLResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="GetHTMLResult" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
I get this error: Cvc-elt.1: Cannot Find The Declaration Of Element 'soap:Envelope'.
Why is this happening?
回答1:
Try checking the SOAP response against the following XSD file. I added elements for the outer <soap:Envelope>
and <soap:Body>
tags which are present in the SOAP response.
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org"
xmlns:tns="http://www.w3.org/2003/05/soap-envelope">
<xs:element name="Envelope" type="tns:envType">
<xs:complexType name="envType">
<xs:sequence>
<xs:element name="Body" type="tns:bodyType">
<xs:complexType name="bodyType">
<xs:sequence>
<xs:element name="GetHTMLResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="GetHTMLResult" minOccurs="0"
maxOccurs="1" type="xs:string">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
来源:https://stackoverflow.com/questions/30839149/xsd-for-soap-result-not-working