使用Schematron识别xml文本元素 [英] Identify xml text elements with Schematron
本文介绍了使用Schematron识别xml文本元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在XPath中制定一条规则来标识像这样的xml元素:
Is it possible to make a rule in XPath which identifies xml elements like this one:
<A>something...<A>
?
我正在使用Schematron,我需要指定某些元素不能像示例中的那样具有子元素,这就是为什么我需要识别它们的原因.
I am using Schematron and I need to specify that some elements must not have children like the one in the example, that's why I need to identify them.
预先感谢
推荐答案
对于以下输入:
<?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>
这些Schematron规则应执行您想要的操作:
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>
这篇关于使用Schematron识别xml文本元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文