我尝试通过特殊属性从 SVG 文档中选择一个元素。我设置了一个简单的例子。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">
<g id='1'>
<path id='2' type='A'/>
<rect id='3' type='B'/>
</g>
</svg>
现在我使用以下语法通过属性“type”检索路径元素:
require 'rexml/document'
include REXML
xmlfile = File.new "xml_as_specified_above.svg"
xmldoc = Document.new(xmlfile)
XPath.match( xmldoc.root, "//path[@type]" )
直接来自http://www.w3schools.com/xpath/xpath_syntax.asp的语法。我希望这个表达式选择路径元素,但如下所示:
>> XPath.match( xmldoc.root, "//path[@type]" )
=> []
那么,在 XPath 中通过属性来寻址路径元素的正确语法是什么?或者 REXML 中是否存在错误(使用 3.1.7.3)?加点还可以检索“rect”元素。