gpt4 book ai didi

Ruby:如何使用 Nokogiri 从 XML 获取属性值?

转载 作者:数据小太阳 更新时间:2023-10-29 08:01:15 26 4
gpt4 key购买 nike

如何获取消息值的值(“准备使用”)?

<?xml version="1.0" encoding="UTF-8"?>
<response status="ok" permission_level="admin" message="ready to use" cached="0">
<title>kit</title>
</response>

谢谢

最佳答案

require 'rubygems'
require 'nokogiri'

string = %Q{
<?xml version="1.0" encoding="UTF-8"?>
<response status="ok" permission_level="admin" message="ready to use" cached="0">
<title>kit</title>
</response>
}

doc = Nokogiri::XML(string)
doc.css("response").each do |response_node|
puts response_node["message"]
end

保存并运行这个ruby文件,你会得到结果:

#=> ready to use

关于Ruby:如何使用 Nokogiri 从 XML 获取属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10119438/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com