如何在 Schematron 中将命名空间和路径组合到元素中?
How to combine namespace and path to element in Schematron?
我可以正确验证这个 XML 文件
<?xml version='1.0' encoding='UTF-8'?>
<world>
<dog>
<ears DIRTY='no'>
</ears>
</dog>
<human>
<ears EARRING='yes'>
</ears>
</human>
</world>
使用此架构
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern>
<rule context='world/human/ears'>
<assert test="@EARRING">ears element in human must have EARRING attribute</assert>
</rule>
<rule context='world/dog/ears'>
<assert test="@DIRTY">ears element in dog must have DIRTY attribute</assert>
</rule>
</pattern>
</schema>
但是当我引入默认命名空间时无法正确验证它。
例如,将其作为 XML 文件:
<?xml version='1.0' encoding='UTF-8'?>
<world xmlns='default-namespace'>
<dog>
<ears DIRTY='no'>
</ears>
</dog>
<human>
<ears EARRING='yes'>
</ears>
</human>
</world>
这是模式:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<ns prefix="mets" uri="default-namespace"/>
<pattern>
<rule context='mets:world/human/ears'>
<assert test="@COLOR">ears element in human must have COLOR attribute</assert>
</rule>
<rule context='mets:world/dog/ears'>
<assert test="@DIRTY">ears element in dog must have DIRTY attribute</assert>
</rule>
</pattern>
</schema>
它应该会失败(@COLOR 缺失),但它不会。
我做错了什么?
每个元素都需要有命名空间前缀。变化:
<rule context='mets:world/human/ears'>
至:
<rule context='mets:world/mets:human/mets:ears'>
我可以正确验证这个 XML 文件
<?xml version='1.0' encoding='UTF-8'?>
<world>
<dog>
<ears DIRTY='no'>
</ears>
</dog>
<human>
<ears EARRING='yes'>
</ears>
</human>
</world>
使用此架构
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern>
<rule context='world/human/ears'>
<assert test="@EARRING">ears element in human must have EARRING attribute</assert>
</rule>
<rule context='world/dog/ears'>
<assert test="@DIRTY">ears element in dog must have DIRTY attribute</assert>
</rule>
</pattern>
</schema>
但是当我引入默认命名空间时无法正确验证它。
例如,将其作为 XML 文件:
<?xml version='1.0' encoding='UTF-8'?>
<world xmlns='default-namespace'>
<dog>
<ears DIRTY='no'>
</ears>
</dog>
<human>
<ears EARRING='yes'>
</ears>
</human>
</world>
这是模式:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<ns prefix="mets" uri="default-namespace"/>
<pattern>
<rule context='mets:world/human/ears'>
<assert test="@COLOR">ears element in human must have COLOR attribute</assert>
</rule>
<rule context='mets:world/dog/ears'>
<assert test="@DIRTY">ears element in dog must have DIRTY attribute</assert>
</rule>
</pattern>
</schema>
它应该会失败(@COLOR 缺失),但它不会。
我做错了什么?
每个元素都需要有命名空间前缀。变化:
<rule context='mets:world/human/ears'>
至:
<rule context='mets:world/mets:human/mets:ears'>