Identify xml text elements with Schematron

笑着哭i 提交于 2019-12-06 17:39:17

For the following input:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <a>Only Text</a>
  <a><b>Child node</b></a>  
  <a><b>Child node</b>Mixed content</a>
</root>

These Schematron rules should do what you want:

<?xml version="1.0" encoding="UTF-8"?>
<iso:schema xmlns:iso="http://purl.oclc.org/dsdl/schematron">
<iso:pattern id="children tests">
    <iso:rule context="a">
        <iso:assert test="child::node()">
            Element has nodes
        </iso:assert>
        <iso:report test="child::*">
            Element has child elements
        </iso:report>
        <iso:assert test="empty(child::text())">
            Element has text
        </iso:assert>
        <iso:report test="child::text() and empty(child::*)">
            Element has only text
        </iso:report>               
    </iso:rule>
</iso:pattern>
</iso:schema>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!