蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

xs:anyAttribute:限定属性与验证模式:逐项真实XSD1.0验证

PYTHONWindows / Python3.12 / xmlschema4.3.2 XMLSchema10 / elementpath5.1.4;lxml6.1.3+libxml2.11.9交叉观察schema-complex-anyattribute.py
schema-complex-anyattribute.py82 行
from schema_lab import run_cases

# 蓝色天空网 mbsky.com:独立输入与逐项预期。
SCENARIOS = [{'id': '1',
  'schema': 'schemas/anyattribute-strict.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" />',
  'expected': True,
  'goal': 'strict 缺省'},
 {'id': '2',
  'schema': 'schemas/anyattribute-strict.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:gender="female"/>',
  'expected': True,
  'goal': 'strict 已知正确'},
 {'id': '3',
  'schema': 'schemas/anyattribute-strict.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:gender="other"/>',
  'expected': False,
  'goal': 'strict 已知错误'},
 {'id': '4',
  'schema': 'schemas/anyattribute-strict.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:unknown="x"/>',
  'expected': False,
  'goal': 'strict 未知'},
 {'id': '5',
  'schema': 'schemas/anyattribute-strict.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" gender="female"/>',
  'expected': False,
  'goal': 'strict 无命名空间'},
 {'id': '6',
  'schema': 'schemas/anyattribute-lax.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" />',
  'expected': True,
  'goal': 'lax 缺省'},
 {'id': '7',
  'schema': 'schemas/anyattribute-lax.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:gender="female"/>',
  'expected': True,
  'goal': 'lax 已知正确'},
 {'id': '8',
  'schema': 'schemas/anyattribute-lax.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:gender="other"/>',
  'expected': False,
  'goal': 'lax 已知错误'},
 {'id': '9',
  'schema': 'schemas/anyattribute-lax.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:unknown="x"/>',
  'expected': True,
  'goal': 'lax 未知'},
 {'id': '10',
  'schema': 'schemas/anyattribute-lax.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" gender="female"/>',
  'expected': False,
  'goal': 'lax 无命名空间'},
 {'id': '11',
  'schema': 'schemas/anyattribute-skip.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" />',
  'expected': True,
  'goal': 'skip 缺省'},
 {'id': '12',
  'schema': 'schemas/anyattribute-skip.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:gender="female"/>',
  'expected': True,
  'goal': 'skip 已知正确'},
 {'id': '13',
  'schema': 'schemas/anyattribute-skip.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:gender="other"/>',
  'expected': True,
  'goal': 'skip 已知错误'},
 {'id': '14',
  'schema': 'schemas/anyattribute-skip.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" e:unknown="x"/>',
  'expected': True,
  'goal': 'skip 未知'},
 {'id': '15',
  'schema': 'schemas/anyattribute-skip.xsd',
  'input': '<person xmlns:e="urn:mbsky:extra" gender="female"/>',
  'expected': False,
  'goal': 'skip 无命名空间'}]

if __name__ == "__main__":
    run_cases('schema-complex-anyattribute', 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-complex-anyattribute.py

预期结果与验证条件观察提示
  • 本章15项主验证结果与逐项预期一致。
  • 具体分支:strict 缺省;strict 已知正确;strict 已知错误;strict 未知;strict 无命名空间;lax 缺省;lax 已知正确;其余分支逐项列于清单与源码。
  • lxml观察可能不同,所有差异保留为处理器限制/后续复核,不能据此升级完整语义或其它处理器。

请结合实际环境逐项观察。

附件与关联工程包下载

下载课程关联工程包:XML Schema

课程关联工程包(登记关联24章) · 含当前章节或实例 · mbskycom202611a529.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习