[英]Savon and Nokogiri parse result
I´m using Savon and Nokogiri to parse SOAP responses. 我正在使用Savon和Nokogiri来解析SOAP响应。
This is my code: 这是我的代码:
response = client.call(:is_resource_available, message: message)
isResourceAvailableXML = response.body[:is_resource_available_response][:out]
@logger.debug "response=" + isResourceAvailableXML.inspect
isResourceAvailableParsed = Nokogiri::XML(isResourceAvailableXML)
isResourceAvailable = isResourceAvailableParsed.xpath("//resource")
@logger.debug "isResourceAvailable=" + isResourceAvailable.inspect
bIsResourceAvailable = isResourceAvailable["isavailable"]
This is the log: 这是日志:
response="<resource id=\"1188200267800225\" isavailable=\"1\" />"
isResourceAvailable=[#<Nokogiri::XML::Element:0x3fd16d979fb8 name="resource" attributes=[#<Nokogiri::XML::Attr:0x3fd16d979db0 name="id" value="1188200267800225">, #<Nokogiri::XML::Attr:0x3fd16d979d9c name="isavailable" value="1">]>]
I´m getting this error: TypeError (no implicit conversion of String into Integer)
我收到此错误:
TypeError (no implicit conversion of String into Integer)
The problem is I'm not getting an array but only a single node, so instead of 问题是我没有得到一个数组,而只有一个节点,所以不是
isResourceAvailable = isResourceAvailableParsed.xpath("//resource")
I should use 我应该用
isResourceAvailable = isResourceAvailableParsed.at_xpath("//resource")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.