目前我正在使用XSD进行SOAP XML,但是当我在FREEFORMATTER.COM上运行SOAP XML和XSD时,我收到此错误:
Cvc-elt.1:找不到元素宣言'肥皂:信封' ...行' 1',栏' 170'
这是我的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>
这是我的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>
如何消除错误?
答案 0 :(得分:2)
首先,您必须将var x = 0;
console.log(++x); // returns 1
console.log(x); // returns 1
添加到XSD的targetNamespace="http://tempuri.org/"
元素,以便将XSD应用于XML有效内容中使用的命名空间。
然后,您可以采用以下任一方法:更改XML 或更改XSD 。根据您控制的文件进行选择。
添加
xs:schema
到xsi:schemaLocation="http://tempuri.org/ tempuri.xsd
http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/
:
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>
到XSD的<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"
schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
元素:
xs:schema
这两种方法都可以成功验证您的SOAP信封及其有效负载。
答案 1 :(得分:0)
也许如果您针对xsd验证xml,则需要将builderFactory初始化为“知道名称空间”-默认情况下为false。
final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
final DocumentBuilder builder = builderFactory.newDocumentBuilder();
builder.parse(...);