from schema_lab import run_cases
# 蓝色天空网 mbsky.com:独立输入与逐项预期。
SCENARIOS = [{'id': '1',
'schema': 'schemas/learning.xsd',
'input': '<learning id="a"><name>蓝天</name><hours>2</hours></learning>',
'expected': True,
'goal': '正确结构'},
{'id': '2',
'schema': 'schemas/learning.xsd',
'input': '<learning id="a"><hours>2</hours><name>蓝天</name></learning>',
'expected': False,
'goal': '错误顺序'},
{'id': '3',
'schema': 'schemas/learning.xsd',
'input': '<learning id="a"><name>蓝天</name><hours>0</hours></learning>',
'expected': False,
'goal': '正整数拒绝0'},
{'id': '4',
'schema': 'schemas/learning.xsd',
'input': '<learning><name>蓝天</name><hours>2</hours></learning>',
'expected': False,
'goal': '缺必需id'},
{'id': '5',
'schema': 'schemas/learning.xsd',
'input': '<learning id="a"><name>蓝天</name><hours>1</hours><hours>2</hours><hours>3</hours></learning>',
'expected': False,
'goal': '超过maxOccurs2'}]
if __name__ == "__main__":
run_cases('schema-intro', SCENARIOS)
本例需在 Windows / Python3.12 / xmlschema4.3.2 XMLSchema10 / elementpath5.1.4;lxml6.1.3+libxml2.11.9交叉观察 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows / Python3.12 / xmlschema4.3.2 XMLSchema10 / elementpath5.1.4;lxml6.1.3+libxml2.11.9交叉观察
入口文件:projects/schema-lab/schema-intro.py
预期结果与验证条件观察提示
- 本章5项主验证结果与逐项预期一致。
- 具体分支:正确结构;错误顺序;正整数拒绝0;缺必需id;超过maxOccurs2。
- lxml观察可能不同,所有差异保留为处理器限制/后续复核,不能据此升级完整语义或其它处理器。
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联24章) · 含当前章节或实例 · mbskycom202611a529.zip