from pathlib import Path
from lxml import etree
B=Path(__file__).resolve().parent
root=etree.parse(str(B/'public/service.wsdl'),etree.XMLParser(resolve_entities=False,no_network=True)).getroot()
W='http://schemas.xmlsoap.org/wsdl/';X='http://www.w3.org/2001/XMLSchema'
messages={e.get('name') for e in root.findall('{'+W+'}message')};ports={e.get('name') for e in root.findall('{'+W+'}portType')};bindings={e.get('name') for e in root.findall('{'+W+'}binding')}
schema=root.find('{'+W+'}types/{'+X+'}schema');elements={e.get('name') for e in schema.findall('{'+X+'}element')}
def reference(e,attribute,names):
value=e.get(attribute);prefix,local=value.split(':',1);assert e.nsmap[prefix]=='urn:mbsky:site';assert local in names,(attribute,value)
for e in root.findall('.//{'+W+'}input')+root.findall('.//{'+W+'}output'):
if e.get('message'):reference(e,'message',messages)
for e in root.findall('{'+W+'}binding'):reference(e,'type',ports)
for e in root.findall('.//{'+W+'}port'):reference(e,'binding',bindings)
for e in root.findall('.//{'+W+'}part'):reference(e,'element',elements)
assert not root.findall('{'+W+'}serviceType')
print({'message_references_resolved':True,'type_references_resolved':True,'historical_serviceType_not_inserted':True,'scope':'owned teaching rules, not a full WSDL validator'})
本例需在 Python 3.12 lxml;PHP 8.4.27 SOAP;回环HTTP 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Python 3.12 lxml;PHP 8.4.27 SOAP;回环HTTP
入口文件:projects/wsdl-lab/inspect_syntax.py
预期结果与验证条件观察提示
- 本章固定结构、引用或目录查找断言成立
- 声明为抽象或本地目录的内容不冒充协议实现
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联8章) · 含当前章节或实例 · mbskycom202611a537.zip