Ruby中使用Nokogiri包来操作XML格式数据的教程(ruby module)这都可以?

随心笔谈3年前 (2023)发布 admin
233 0


[email protected]_css(‘title’)
[email protected](‘book’).last

# 可以把第一个title放到第二个book中
first_title.parent=second_book

# 也可以随意摆放。
second_book.add_next_sibling(first_title)

# 也可以修改对应的class
first_title.name=’h2′
first_title[‘class’]=’red_color’
puts @doc.to_html
#=> <h2 class=’red_color’>…</h2>

# 也可以新建一个node
third_book=Nokogiri::XML::Node.new ‘book’, @doc
third_book.content=’I am the third book’
second_book.add_next_sibling third_book
puts @doc.to_html
#=>

<books>

<book>I am the third book</book>
</books>

© 版权声明

相关文章

暂无评论

暂无评论...