【发布时间】:2020-11-24 15:54:27
【问题描述】:
我正在对 XML 文件使用 schematron 验证。我尝试编写我的第一条规则,并使用在线工具https://www.liquid-technologies.com/online-schematron-validator 进行检查。这条规则有什么问题?我想要做的是验证图片节点是否存在,如果它存在,它是否有一些文本,所以它不能是这样的:<Picture/>,而是<Picture>aasd</Picture>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Message>
<book>
<chapterA>
<SectionA>
<Picture>picture</Picture>
</SectionA>
</chapterA>
</book>
</Message>
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>Myrule</title>
<pattern>
<rule context="Message">
<assert test="boolean(/*[local-name() = 'book']/*[local-name() = 'chapterA']/*[local-name() = 'SectionA']/*[local-name() = 'Picture'])" flag="fatal" id="id123">[123] Picture obligatory</assert>
</rule>
</pattern>
</schema>
【问题讨论】:
标签: xml xsd xml-validation schematron