我有这样简单的XML文件:
<screen>
<object attribute="String"/>
<object attribute="Relationship">
<vertices>
<vertex point_index="1" x="18" y="30" />
<vertex point_index="2" x="91" y="30" />
<vertex point_index="3" x="91" y="60" />
<vertex point_index="4" x="18" y="60" />
</vertices>
</object>
</screen>
如何正确使用XPath(1.0)count()函数接收具有指定类型的对象中的顶点计数?我正在尝试使用以下字符串,但在线XPath测试工具(http://www.xpathtester.com/test)返回错误。
count(/screen/object[@attribute="Relationship"]/vertices/*)
什么似乎错了?
答案 0 :(得分:2)
XPath没有任何问题。只是您使用的测试工具无法返回数字作为结果。请尝试使用此测试工具:http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm