Validation SAXParseException无法将SOAP-ENC:数组解析为类型定义组件
我正在尝试根据WSDL验证SOAP响应消息,并遵循给定的示例。然而,我得到下面的例外Validation SAXParseException无法将SOAP-ENC:数组解析为类型定义组件,validation,wsdl,xsd,Validation,Wsdl,Xsd,我正在尝试根据WSDL验证SOAP响应消息,并遵循给定的示例。然而,我得到下面的例外 org.xml.sax.SAXParseException:src resolve:无法将名称“SOAP-ENC:Array”解析为(n)“类型定义”组件。 我见过类似的错误,但我不确定这是否是同一个问题。我也不明白为什么SOAP-ENC:Array出现在 这是我的验证代码。在Schema Schema=schemaFactory.newSchema(schemas)行上引发异常 DocumentBuilder
org.xml.sax.SAXParseException:src resolve:无法将名称“SOAP-ENC:Array”解析为(n)“类型定义”组件。
我见过类似的错误,但我不确定这是否是同一个问题。我也不明白为什么SOAP-ENC:Array
出现在
这是我的验证代码。在Schema Schema=schemaFactory.newSchema(schemas)
行上引发异常
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document wsdlDoc = db.newDocument();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source wsdlSource = new StreamSource(new File("d:\\temp\\demo.wsdl"));
transformer.transform(wsdlSource, new DOMResult(wsdlDoc));
NodeList schemaNodes = wsdlDoc.getElementsByTagNameNS(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema");
int nrSchemas = schemaNodes.getLength();
Source[] schemas = new Source[nrSchemas];
for (int i = 0; i < nrSchemas; ++i)
{
schemas[i] = new DOMSource(schemaNodes.item(i));
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemas);
Validator validator = schema.newValidator();
Source soapMessage = new StreamSource(new File("d:\\temp\\soapmessage.xml"));
Result result = new StreamResult(System.out);
validator.validate(soapMessage, result);
DocumentBuilder db=DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document wsdlDoc=db.newDocument();
TransformerFactory TransformerFactory=TransformerFactory.newInstance();
Transformer Transformer=transformerFactory.newTransformer();
Source wsdlSource=newstreamsource(新文件(“d:\\temp\\demo.wsdl”);
transform(wsdlSource,newdomresult(wsdlDoc));
NodeList schemaNodes=wsdlDoc.getelementsbytagnames(xmlstants.W3C_XML_SCHEMA_NS_URI,“SCHEMA”);
int nrSchemas=schemaNodes.getLength();
Source[]schemas=新源[nrSchemas];
对于(int i=0;i
我删减了WSDL,只留下了相关部分,或者至少是我认为相关的部分。如果需要更多,我将更新问题
<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="run:demo"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="run:demo">
<types>
<xsd:schema targetNamespace="run:demo">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
<xsd:complexType name="itemsCT">
<xsd:all>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="Address" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="itemsArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType"
wsdl:arrayType="tns:itemsCT[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</types>
</definitions>
直接的问题是,被调用的模式验证器没有为名称空间加载任何模式文档——这可能是因为它是一个通用验证器,没有任何关于SOAP名称空间的内置知识,也可能是因为它没有从schemas.xmlsoap.org上的服务器检索到模式文档 如果您有和名称空间的模式的本地副本,则可以尝试向模式中的两个xsd:import元素添加模式位置信息。如果您没有本地副本,那么我希望您从schemas.xmlsoap.org获得响应的运气比我刚才好