xml - 为什么我的 xsd 验证未声明的属性?
问题描述
我有一个 xml,我想在添加新属性后针对 xsd 进行验证。
我试图为 xsd 中的某些元素在本地声明属性,但不知道该怎么做。
一时兴起,我拿了一个已经验证过的 xml 并将新属性添加到一个元素,而不对 xsd 进行任何更改,并且验证成功通过。
属性(字母间距)仅通过了验证,它具有命名空间前缀(命名空间 'dptt' 在 xsd 中定义并出现在 xml 中):
通过验证的行示例:
<tt:style dptt:letter-spacing="4px" style="s01" tts:lineHeight="120px" xml:id="1"/>
未通过验证的行示例:
<tt:style letter-spacing="4px" style="s01" tts:lineHeight="120px" xml:id="1"/>
这是定义样式属性的 xsd 部分:
<xs:element name="style">
<xs:complexType>
<xs:sequence>
<xs:element ref="tt:metadata" minOccurs="0"/>
</xs:sequence>
<xs:attribute ref="xml:id" use="required">
</xs:attribute>
<xs:attribute name="style" type="xs:IDREFS">
</xs:attribute>
<xs:attribute ref="tts:direction" >
</xs:attribute>
<xs:attribute ref="tts:fontFamily" >
</xs:attribute>
<xs:attribute ref="tts:fontSize" >
</xs:attribute>
<xs:attribute ref="tts:lineHeight" >
</xs:attribute>
<xs:attribute ref="tts:textAlign" >
</xs:attribute>
<xs:attribute ref="tts:color" >
</xs:attribute>
<xs:attribute ref="tts:backgroundColor" >
</xs:attribute>
<xs:attribute ref="tts:fontStyle" >
</xs:attribute>
<xs:attribute ref="tts:fontWeight" >
</xs:attribute>
<xs:attribute ref="tts:textDecoration" >
</xs:attribute>
<xs:attribute ref="tts:unicodeBidi" >
</xs:attribute>
<xs:attribute ref="tts:padding">
</xs:attribute>
<xs:attribute ref="ebutts:multiRowAlign"/>
</xs:complexType>
</xs:element>
我希望未声明的属性不会通过验证。
我还想知道为什么添加命名空间对于验证至关重要。
解决方案
没有看到我们不可能知道的模式。我的猜测是包含元素的复杂类型包括xs:anyAttribute
通配符。
推荐阅读
- javascript - 即使对象已在 JavaScript 中被替换,如何监听事件
- vue.js - 防止 nuxt auth 将授权标头发送到外部 url
- apache-kafka - 如果我的业务逻辑需要很长时间来处理第一个偏移量的数据,Kafka 不轮询偏移量属于同一个分区
- python - tkinter - LabelFrame 不显示标签
- c# - 在大量 nvarchar(max) 上提高 SqlBulkCopy 性能
- beautifulsoup - 使用 BeautifulSoup 从 WSJ 获取新闻
- c# - 提示选项无效,因为进程不是交互式的
- reactjs - React Native 如何以编程方式打开 react-native-dropdown-picker
- keras - BATCHNORM 朝向 pytorch 中的轴
- ansible - Ansible 和 Opennebula:https://myopennebulaserver/RPC2 的 ProtocolError:401 401 客户端错误:未经授权