考慮下面的XML已被解析成@response
using Nokogiri使用Nokogiri檢查xml響應是否有type =「array」?
<?xml version="1.0" encoding="UTF-8"?>
<foos type="array">
<foo>
<id type="integer">1</id>
<name>bar</name>
</foo>
</foos>
的是否存在xpath
這樣@response.xpath(xpath)
回報array
?
假設這個xpath必須在foo的命名不一致的多個文檔中重用。
如果xpath不是解決此問題的正確工具,Nokogiri是否提供了一種方法?
此xml由rails框架自動生成,並且此問題的答案旨在用於創建與this Cucumber feature for JSON responses等效的XML。