2013-02-01 49 views
1

是否有可能作出的XPath规则识别这样一个XML元素:识别XML文本元素使用Schematron

<A>something...<A> 

我正在使用Schematron,我需要指定某些元素不能像例子中那样有子元素,这就是为什么我需要识别它们。

在此先感谢

回答

2

对于以下输入:

<?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的规则应该做你想要什么:

<?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> 

Testing Schematron rules in XML ValidatorBuddy