简体   繁体   中英

Convert String to Nokogiri node

Is it possible to convert a string looking like this : "<count>2</count>" in Nokogiri node <count>2</count> ? Thanks in advance.

Yes and it's quite straightforward, just do

Nokogiri::XML("<count>2</count>")

For instance:

pry(main)> Nokogiri::XML("<count>2</count>").children.first.to_s                                              
=> "<count>2</count>"                                                                                             

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM