为 SOAP 响应创建 XSD
Create XSD for SOAP Response
我想创建一个 XSD 来验证 SOAP 响应 (XML)。但是,我遇到了错误 - "Cannot Find The Declaration Of Element 'soap:Envelope'"。我尝试将 soap:Envelope 元素添加到 XSD,但出现此错误 - “'soap:Envelope' 不是 'NCName' 的有效值”。
我的XML如下:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetValidOrdersBySalesOppAndLocationResponse xmlns="http://www.webserviceX.NET">
<GetValidOrdersBySalesOppAndLocationResult>
<Order>
<ASV__c>0</ASV__c>
<Date_Submitted__c>2015-08-25T11:02:07</Date_Submitted__c>
<Order_Id>1365577</Order_Id>
<End_Date__c>0001-01-01T00:00:00</End_Date__c>
<Entitlement_Length__c>0</Entitlement_Length__c>
</Order>
<Order>
<ASV__c>0</ASV__c>
<Date_Submitted__c>2015-08-24T23:11:19.75</Date_Submitted__c>
<Order_Id>1365580</Order_Id>
<End_Date__c>0001-01-01T00:00:00</End_Date__c>
<Entitlement_Length__c>0</Entitlement_Length__c>
</Order>
<Order>
<ASV__c>0</ASV__c>
<Date_Submitted__c>2015-08-25T11:19:10</Date_Submitted__c>
<Order_Id>1365581</Order_Id>
<End_Date__c>0001-01-01T00:00:00</End_Date__c>
<Entitlement_Length__c>0</Entitlement_Length__c>
</Order>
</GetValidOrdersBySalesOppAndLocationResult>
</GetValidOrdersBySalesOppAndLocationResponse>
</soap:Body>
</soap:Envelope>
我的XSD如下:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="GetValidOrdersBySalesOppAndLocationResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="GetValidOrdersBySalesOppAndLocationResult">
<xs:complexType>
<xs:sequence>
<xs:element name="Order" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="ASV__c"/>
<xs:element type="xs:dateTime" name="Date_Submitted__c"/>
<xs:element type="xs:int" name="Order_Id"/>
<xs:element type="xs:dateTime" name="End_Date__c"/>
<xs:element type="xs:byte" name="Entitlement_Length__c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我使用了在线 XSD 生成器 - http://www.freeformatter.com/xsd-generator.html and Validator - http://www.freeformatter.com/xml-validator-xsd.html。
我还查看了其他 Whosebug 问题。有一个与我的问题类似的确切问题,但是它没有可以在这里找到的有效解决方案 - XSD for soap result not working。由于我的低点,我无法评论要求 OP 更新。请帮忙。
更新:
添加导入成功!
工作代码(添加了第二行):
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/> //Added import
<xs:element name="GetValidOrdersBySalesOppAndLocationResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="GetValidOrdersBySalesOppAndLocationResult">
<xs:complexType>
<xs:sequence>
<xs:element name="Order" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="ASV__c"/>
<xs:element type="xs:dateTime" name="Date_Submitted__c"/>
<xs:element type="xs:int" name="Order_Id"/>
<xs:element type="xs:dateTime" name="End_Date__c"/>
<xs:element type="xs:byte" name="Entitlement_Length__c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
您应该考虑使用原始 XSD 的 SOAP 信封并使用它。然后使用 xs:import
扩展到您自己的 XSD 您想要验证的必要数据类型。使用 SOAP XSD 将允许您验证任何 SOAP 请求。要验证您自己的类型,只需为通用部分添加您自己的类型。
更好的方法通常是只验证自定义部分,因为如果信封不是有效的 SOAP,任何符合 SOAP 的服务服务器或客户端都会抛出错误。如果您只专注于该部分,还可以节省您的时间。
我想创建一个 XSD 来验证 SOAP 响应 (XML)。但是,我遇到了错误 - "Cannot Find The Declaration Of Element 'soap:Envelope'"。我尝试将 soap:Envelope 元素添加到 XSD,但出现此错误 - “'soap:Envelope' 不是 'NCName' 的有效值”。
我的XML如下:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetValidOrdersBySalesOppAndLocationResponse xmlns="http://www.webserviceX.NET">
<GetValidOrdersBySalesOppAndLocationResult>
<Order>
<ASV__c>0</ASV__c>
<Date_Submitted__c>2015-08-25T11:02:07</Date_Submitted__c>
<Order_Id>1365577</Order_Id>
<End_Date__c>0001-01-01T00:00:00</End_Date__c>
<Entitlement_Length__c>0</Entitlement_Length__c>
</Order>
<Order>
<ASV__c>0</ASV__c>
<Date_Submitted__c>2015-08-24T23:11:19.75</Date_Submitted__c>
<Order_Id>1365580</Order_Id>
<End_Date__c>0001-01-01T00:00:00</End_Date__c>
<Entitlement_Length__c>0</Entitlement_Length__c>
</Order>
<Order>
<ASV__c>0</ASV__c>
<Date_Submitted__c>2015-08-25T11:19:10</Date_Submitted__c>
<Order_Id>1365581</Order_Id>
<End_Date__c>0001-01-01T00:00:00</End_Date__c>
<Entitlement_Length__c>0</Entitlement_Length__c>
</Order>
</GetValidOrdersBySalesOppAndLocationResult>
</GetValidOrdersBySalesOppAndLocationResponse>
</soap:Body>
</soap:Envelope>
我的XSD如下:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="GetValidOrdersBySalesOppAndLocationResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="GetValidOrdersBySalesOppAndLocationResult">
<xs:complexType>
<xs:sequence>
<xs:element name="Order" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="ASV__c"/>
<xs:element type="xs:dateTime" name="Date_Submitted__c"/>
<xs:element type="xs:int" name="Order_Id"/>
<xs:element type="xs:dateTime" name="End_Date__c"/>
<xs:element type="xs:byte" name="Entitlement_Length__c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我使用了在线 XSD 生成器 - http://www.freeformatter.com/xsd-generator.html and Validator - http://www.freeformatter.com/xml-validator-xsd.html。
我还查看了其他 Whosebug 问题。有一个与我的问题类似的确切问题,但是它没有可以在这里找到的有效解决方案 - XSD for soap result not working。由于我的低点,我无法评论要求 OP 更新。请帮忙。
更新: 添加导入成功!
工作代码(添加了第二行):
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/> //Added import
<xs:element name="GetValidOrdersBySalesOppAndLocationResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="GetValidOrdersBySalesOppAndLocationResult">
<xs:complexType>
<xs:sequence>
<xs:element name="Order" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="ASV__c"/>
<xs:element type="xs:dateTime" name="Date_Submitted__c"/>
<xs:element type="xs:int" name="Order_Id"/>
<xs:element type="xs:dateTime" name="End_Date__c"/>
<xs:element type="xs:byte" name="Entitlement_Length__c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
您应该考虑使用原始 XSD 的 SOAP 信封并使用它。然后使用 xs:import
扩展到您自己的 XSD 您想要验证的必要数据类型。使用 SOAP XSD 将允许您验证任何 SOAP 请求。要验证您自己的类型,只需为通用部分添加您自己的类型。
更好的方法通常是只验证自定义部分,因为如果信封不是有效的 SOAP,任何符合 SOAP 的服务服务器或客户端都会抛出错误。如果您只专注于该部分,还可以节省您的时间。