我有一个用来存储XML的值。
我想在XML中搜索这个值:
<transaction_type>authorize</transaction_type>
<transaction_type>authorize3d</transaction_type>如果有值"3d“,我想要编辑XML文件。如果没有的话,我想把它寄出去。
def web_request(request_body)
//Search here in request body for 3d value
if request_body.include? "3d"
puts "String include '3d'"
else
puts "String does not include '3d'"
end
.........
request_body
end我怎样才能正确地实现它呢?
发布于 2017-11-15 20:52:12
使用正则表达式查找包含3d文本的节点:
if request_body =~ /<transaction_type>.*?3d<\/transaction_type>/您也可以使用Nokogiri解析xml并找到具有此值的节点,但在您的示例中,这是开销。
https://stackoverflow.com/questions/47307649
复制相似问题