我正在调用 web 服务,我想通过 xsd 验证来验证 soap 响应。我真的不想进行严格的 xsd 验证,我只想知道响应中是否存在某些元素“历史”。
因此,当存在“历史元素”时,xsd 验证应该成功,而当该元素不存在时,验证应该失败。我一直从下面的 xsd 开始。我只想用我强制的“历史”元素来扩展它。我怎样才能做到这一点?
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
targetNamespace="http://schemas.xmlsoap.org/soap/envelope/"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="Envelope">
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
肥皂反应
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p793:TuDetailsResponse xmlns:p793="http://gls-group.eu/Tracking/">
<p793:History>
<p793:Date>
<p793:Year>2012</p793:Year>
<p793:Month>10</p793:Month>
<p793:Day>12</p793:Day>
<p793:Hour>9</p793:Hour>
<p793:Minut>52</p793:Minut>
<p793:ReasonName/>
</p793:History>
<p793:History>
<p793:Date>
<p793:Year>2012</p793:Year>
<p793:Month>10</p793:Month>
<p793:Day>12</p793:Day>
<p793:Hour>5</p793:Hour>
<p793:Minut>45</p793:Minut>
</p793:Date>
<p793:ReasonName/>
</p793:History>
</p793:TuDetailsResponse>
</soapenv:Body>
</soapenv:Envelope>