提问人:AK2412 提问时间:5/18/2023 最后编辑:AK2412 更新时间:5/18/2023 访问量:105
XSD 验证失败
XSD validation failure
问:
我正在努力使用下面的 java 函数针对 XSD 验证 XML。但是,我在以下行中低于异常。架构架构 = factory.newSchema(new File(xsdPath))。请找到随附的 XSD 和 XML。
异常:s4s-elt-schema-ns:元素“definitions”的命名空间必须来自架构命名空间“http://www.w3.org/2001/XMLSchema”。附有屏幕截图、XSD 和 XML。
代码片段:
public static boolean validateXMLSchema(String xsdPath, String xmlPath){
try {
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File(xsdPath));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(xmlPath)));
} catch (IOException | SAXException e) {
System.out.println("Exception: "+e.getMessage());
return false;
}
return true;
}
XSD:
<?xml version="1.0"?>
<wsdl:definitions targetNamespace="http://google.com/cl/cc/webservices/exposure/AB_IExposureAPI_v1" name="AB_IExposureAPI_v1" xmlns:gwsoap="http://guidewire.com/ws/soapheaders" xmlns:gwwsdl="http://guidewire.com/pl/wsdl" xmlns:pogo="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest" xmlns:pogo2="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse" xmlns:pogo3="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error" xmlns:pogo4="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure" xmlns:pogo5="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen" xmlns:pogo6="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose" xmlns:soap11="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://google.com/cl/cc/webservices/exposure/AB_IExposureAPI_v1" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xs:schema targetNamespace="http://google.com/cl/cc/webservices/exposure/AB_IExposureAPI_v1" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://guidewire.com/ws/soapheaders" schemaLocation="../../../../../../../gw/xsd/guidewire/soapheaders.xsd"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest"/>
<!-- getExposures(ExposureRequest) : ExposureResponse -->
<xs:element name="getExposures">
<xs:complexType>
<xs:sequence>
<xs:element name="request" type="pogo:ExposureRequest" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getExposuresResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" type="pogo2:ExposureResponse" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="WsiAuthenticationException">
<xs:complexType/>
</xs:element>
<!-- reopenExposure(ExposureRequestToReopen) : ExposureResponse -->
<xs:element name="reopenExposure">
<xs:complexType>
<xs:sequence>
<xs:element name="request" type="pogo5:ExposureRequestToReopen" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="reopenExposureResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" type="pogo2:ExposureResponse" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- closeExposure(ExposureRequestToClose) : ExposureResponse -->
<xs:element name="closeExposure">
<xs:complexType>
<xs:sequence>
<xs:element name="request" type="pogo6:ExposureRequestToClose" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="closeExposureResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="return" type="pogo2:ExposureResponse" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema targetNamespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse"/>
<xs:complexType name="ExposureRequest">
<xs:sequence>
<xs:element name="ClaimNumber" type="xs:string" minOccurs="0"/>
<xs:element name="ExposureId" type="xs:string" minOccurs="0"/>
<xs:element name="ExposureNumber" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema targetNamespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest"/>
<xs:complexType name="ExposureResponse">
<xs:sequence>
<xs:element name="Errors" minOccurs="0" gw:viewas="array" xmlns:gw="http://guidewire.com/xsd">
<xs:complexType>
<xs:sequence>
<xs:element name="Entry" type="pogo3:Error" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Exposures" minOccurs="0" gw:viewas="array" xmlns:gw="http://guidewire.com/xsd">
<xs:complexType>
<xs:sequence>
<xs:element name="Entry" type="pogo4:Exposure" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ResponseStatus" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema targetNamespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest"/>
<xs:complexType name="Error">
<xs:sequence>
<xs:element name="Code" type="xs:string" minOccurs="0"/>
<xs:element name="Description" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema targetNamespace="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure" elementFormDefault="qualified" xmlns:gw="http://guidewire.com/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest"/>
<xs:complexType name="Exposure">
<xs:sequence>
<xs:element name="AssignedUserId" type="xs:string" minOccurs="0"/>
<xs:element name="ClaimNumber" type="xs:string" minOccurs="0"/>
<xs:element name="CoverageCode" type="xs:string" minOccurs="0"/>
<xs:element name="Id" type="xs:string" minOccurs="0"/>
<xs:element name="IncidentID" type="xs:string" minOccurs="0"/>
<xs:element name="Name" type="xs:string" minOccurs="0"/>
<xs:element name="Number" type="xs:string" minOccurs="0"/>
<xs:element name="ReopenDate" type="xs:dateTime" minOccurs="0" gw:type="java.util.Date"/>
<xs:element name="SegmentCode" type="xs:string" minOccurs="0"/>
<xs:element name="StatusCode" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema targetNamespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest"/>
<xs:complexType name="ExposureRequestToReopen">
<xs:sequence>
<xs:element name="Description" type="xs:string" minOccurs="0"/>
<xs:element name="Exposure" type="pogo:ExposureRequest" minOccurs="0"/>
<xs:element name="ReasonCode" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema targetNamespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToClose" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequestToReopen"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/domain/Exposure"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/Error"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureResponse"/>
<xs:import namespace="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest"/>
<xs:complexType name="ExposureRequestToClose">
<xs:sequence>
<xs:element name="Description" type="xs:string" minOccurs="0"/>
<xs:element name="Exposure" type="pogo:ExposureRequest" minOccurs="0"/>
<xs:element name="OutcomeCode" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:portType name="AB_IExposureAPI_v1PortType">
<wsdl:operation name="getExposures">
<wsdl:input name="getExposures" message="tns:getExposures"/>
<wsdl:output name="getExposuresResponse" message="tns:getExposuresResponse"/>
<wsdl:fault name="WsiAuthenticationException" message="tns:WsiAuthenticationException"/>
</wsdl:operation>
<wsdl:operation name="reopenExposure">
<wsdl:input name="reopenExposure" message="tns:reopenExposure"/>
<wsdl:output name="reopenExposureResponse" message="tns:reopenExposureResponse"/>
<wsdl:fault name="WsiAuthenticationException" message="tns:WsiAuthenticationException"/>
</wsdl:operation>
<wsdl:operation name="closeExposure">
<wsdl:input name="closeExposure" message="tns:closeExposure"/>
<wsdl:output name="closeExposureResponse" message="tns:closeExposureResponse"/>
<wsdl:fault name="WsiAuthenticationException" message="tns:WsiAuthenticationException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AB_IExposureAPI_v1Soap12Binding" type="tns:AB_IExposureAPI_v1PortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getExposures">
<soap12:operation soapActionRequired="false" style="document"/>
<wsdl:input name="getExposures">
<soap12:body use="literal"/>
<soap12:header message="tns:gw-authentication" part="gw-authentication" use="literal"/>
<soap12:header message="tns:gw-language-only" part="gw-language-only" use="literal"/>
<soap12:header message="tns:gw-locale-only" part="gw-locale-only" use="literal"/>
<soap12:header message="tns:gw-traceability-id" part="gw-traceability-id" use="literal"/>
</wsdl:input>
<wsdl:output name="getExposuresResponse">
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WsiAuthenticationException">
<soap12:fault name="WsiAuthenticationException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="reopenExposure">
<soap12:operation soapActionRequired="false" style="document"/>
<wsdl:input name="reopenExposure">
<soap12:body use="literal"/>
<soap12:header message="tns:gw-authentication" part="gw-authentication" use="literal"/>
<soap12:header message="tns:gw-language-only" part="gw-language-only" use="literal"/>
<soap12:header message="tns:gw-locale-only" part="gw-locale-only" use="literal"/>
<soap12:header message="tns:gw-traceability-id" part="gw-traceability-id" use="literal"/>
</wsdl:input>
<wsdl:output name="reopenExposureResponse">
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WsiAuthenticationException">
<soap12:fault name="WsiAuthenticationException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="closeExposure">
<soap12:operation soapActionRequired="false" style="document"/>
<wsdl:input name="closeExposure">
<soap12:body use="literal"/>
<soap12:header message="tns:gw-authentication" part="gw-authentication" use="literal"/>
<soap12:header message="tns:gw-language-only" part="gw-language-only" use="literal"/>
<soap12:header message="tns:gw-locale-only" part="gw-locale-only" use="literal"/>
<soap12:header message="tns:gw-traceability-id" part="gw-traceability-id" use="literal"/>
</wsdl:input>
<wsdl:output name="closeExposureResponse">
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WsiAuthenticationException">
<soap12:fault name="WsiAuthenticationException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="AB_IExposureAPI_v1Soap11Binding" type="tns:AB_IExposureAPI_v1PortType">
<soap11:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="getExposures">
<soap11:operation style="document"/>
<wsdl:input name="getExposures">
<soap11:body use="literal"/>
<soap11:header message="tns:gw-authentication" part="gw-authentication" use="literal"/>
<soap11:header message="tns:gw-language-only" part="gw-language-only" use="literal"/>
<soap11:header message="tns:gw-locale-only" part="gw-locale-only" use="literal"/>
<soap11:header message="tns:gw-traceability-id" part="gw-traceability-id" use="literal"/>
</wsdl:input>
<wsdl:output name="getExposuresResponse">
<soap11:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WsiAuthenticationException">
<soap11:fault name="WsiAuthenticationException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="reopenExposure">
<soap11:operation style="document"/>
<wsdl:input name="reopenExposure">
<soap11:body use="literal"/>
<soap11:header message="tns:gw-authentication" part="gw-authentication" use="literal"/>
<soap11:header message="tns:gw-language-only" part="gw-language-only" use="literal"/>
<soap11:header message="tns:gw-locale-only" part="gw-locale-only" use="literal"/>
<soap11:header message="tns:gw-traceability-id" part="gw-traceability-id" use="literal"/>
</wsdl:input>
<wsdl:output name="reopenExposureResponse">
<soap11:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WsiAuthenticationException">
<soap11:fault name="WsiAuthenticationException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="closeExposure">
<soap11:operation style="document"/>
<wsdl:input name="closeExposure">
<soap11:body use="literal"/>
<soap11:header message="tns:gw-authentication" part="gw-authentication" use="literal"/>
<soap11:header message="tns:gw-language-only" part="gw-language-only" use="literal"/>
<soap11:header message="tns:gw-locale-only" part="gw-locale-only" use="literal"/>
<soap11:header message="tns:gw-traceability-id" part="gw-traceability-id" use="literal"/>
</wsdl:input>
<wsdl:output name="closeExposureResponse">
<soap11:body use="literal"/>
</wsdl:output>
<wsdl:fault name="WsiAuthenticationException">
<soap11:fault name="WsiAuthenticationException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AB_IExposureAPI_v1">
<wsdl:port name="AB_IExposureAPI_v1Soap12Port" binding="tns:AB_IExposureAPI_v1Soap12Binding">
<soap12:address location="https://navigator.dev-a.abcec.com/cc/ws/com/abc/pm/cl/cc/webservices/exposure/AB_IExposureAPI_v1"/>
<gwwsdl:address location="${cc}/ws/com/abc/pm/cl/cc/webservices/exposure/AB_IExposureAPI_v1"/>
</wsdl:port>
<wsdl:port name="AB_IExposureAPI_v1Soap11Port" binding="tns:AB_IExposureAPI_v1Soap11Binding">
<soap11:address location="https://navigator.dev-a.abcec.com/cc/ws/com/abc/pm/cl/cc/webservices/exposure/AB_IExposureAPI_v1/soap11"/>
<gwwsdl:address location="${cc}/ws/com/abc/pm/cl/cc/webservices/exposure/AB_IExposureAPI_v1/soap11"/>
</wsdl:port>
</wsdl:service>
<wsdl:message name="getExposures">
<wsdl:part name="parameters" element="tns:getExposures"/>
</wsdl:message>
<wsdl:message name="getExposuresResponse">
<wsdl:part name="parameters" element="tns:getExposuresResponse"/>
</wsdl:message>
<wsdl:message name="WsiAuthenticationException">
<wsdl:part name="WsiAuthenticationException" element="tns:WsiAuthenticationException"/>
</wsdl:message>
<wsdl:message name="reopenExposure">
<wsdl:part name="parameters" element="tns:reopenExposure"/>
</wsdl:message>
<wsdl:message name="reopenExposureResponse">
<wsdl:part name="parameters" element="tns:reopenExposureResponse"/>
</wsdl:message>
<wsdl:message name="closeExposure">
<wsdl:part name="parameters" element="tns:closeExposure"/>
</wsdl:message>
<wsdl:message name="closeExposureResponse">
<wsdl:part name="parameters" element="tns:closeExposureResponse"/>
</wsdl:message>
<wsdl:message name="gw-authentication">
<wsdl:part name="gw-authentication" element="gwsoap:authentication"/>
</wsdl:message>
<wsdl:message name="gw-locale-only">
<wsdl:part name="gw-locale-only" element="gwsoap:gw_locale"/>
</wsdl:message>
<wsdl:message name="gw-language-only">
<wsdl:part name="gw-language-only" element="gwsoap:gw_language"/>
</wsdl:message>
<wsdl:message name="gw-transaction-id">
<wsdl:part name="gw-transaction-id" element="gwsoap:transaction_id"/>
</wsdl:message>
<wsdl:message name="gw-traceability-id">
<wsdl:part name="gw-traceability-id" element="gwsoap:traceability_id"/>
</wsdl:message>
</wsdl:definitions>
XML格式:
<?xml version="1.0"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soap1="http://guidewire.com/ws/soapheaders" xmlns:AB="http://google.com/cl/cc/webservices/exposure/AB_IExposureAPI_v1" xmlns:exp="http://google.com/cl/cc/webservices/exposure/model/v1/service/ExposureRequest"><soap:Header><soap1:authentication><soap1:username>su</soap1:username><soap1:password>gw</soap1:password></soap1:authentication></soap:Header><soap:Body><AB:getExposures><AB:request><exp:ClaimNumber>123</exp:ClaimNumber><exp:ExposureId>1</exp:ExposureId><exp:ExposureNumber>01</exp:ExposureNumber></AB:request></AB:getExposures></soap:Body></soap:Envelope>
答:
0赞
Martin Honnen
5/18/2023
#1
显示的代码示例不是 W3C XSD 架构,而是包含此类架构的各个部分,或者似乎包含各种架构。也许 WSDL 工具知道如何处理这样的输入格式,但基于 XSD 的验证器肯定不会这样做。
评论
0赞
AK2412
5/18/2023
有没有办法为WSDL工具编写代码,将此XSD视为有效类型?如果没有,那么有什么选择?
0赞
Martin Honnen
5/18/2023
@AK2412,很抱歉,我对 WSDL 的了解还不够,无法分辨出哪个工具或某个工具是否知道如何验证您的输入。正如我所说,它不是一个 XSD 架构,而是具有一些其他元素,然后包含 XSD 架构。
评论