[英]Graticule and Rails: REXML::ParseException: missing attribute quote
[英]Get same attribute values with rexml
快速提問。
假設您有一個類似xml的文件:
<ItemAttributes>
<Author>John Green</Author>
<Author>David Levithan</Author>
<Binding>Hardcover</Binding>
<Brand>Dutton Juvenile</Brand>
<EAN>9780525421580</EAN>
</ItemAttributes>
我正在使用rexml對其進行解析。 我在獲取相同屬性的值時陷入困境。 當我做:
doc = REXML::Document.new(xml_data)
doc.elements['ItemAttributes/Author/'].each do |element|
logger.info(element)
end
它只給我第一個屬性值,即約翰·格林。 如何獲得相同屬性(“作者”)的第二個值。 我也嘗試過使用“ *”,但沒有成功。
有什么想法嗎?
嘗試這個:
doc.elements.each("ItemAttributes/Author") do |author|
logger.info(author.text)
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.