Ruby on rails 使用Nokogiri捕获XML响应
我正在尝试一个功能,在这个功能中,我获得了一个针对successone消息和failuremultiple response消息的XML响应,但我无法使用nokogiri在rails代码中捕获这些消息以下是我从XML响应中获得的消息 对于失败,我还可以得到其他失败消息Ruby on rails 使用Nokogiri捕获XML响应,ruby-on-rails,nokogiri,Ruby On Rails,Nokogiri,我正在尝试一个功能,在这个功能中,我获得了一个针对successone消息和failuremultiple response消息的XML响应,但我无法使用nokogiri在rails代码中捕获这些消息以下是我从XML响应中获得的消息 对于失败,我还可以得到其他失败消息 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <status> <error> Such username is allre
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<status>
<error> Such username is allready taken </error>
</status>
任何人如果有任何想法都可以救我一天。这可以帮助你
case res
when Net::HTTPSuccess, Net::HTTPRedirection
@doc = Nokogiri::XML(data)
@doc.xpath('/status/success').each do |oop|
@ee = oop.content
end
if @ee.nil?
@doc.xpath('/status/error').each do |link|
@status = link.content
end
flash[:notice] = @status
render "new"
else
flash[:notice] = @ee
redirect_to "/"
end
end
def create
@user = User.new(params[:user])
a = "https://www.example.com"
url = URI.parse(a)
http = Net::HTTP.new( url.host, url.port )
http.use_ssl = true if url.port == 443
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if url.port == 443
path = url.path + "?" + "request_query"
res, data = http.get( path )
case res
when Net::HTTPSuccess, Net::HTTPRedirection
doc = Nokogiri::XML(data)
doc.xpath('/status/success').each do |link|
@abc = link.content
end
flash[:notice] = @abc
if @abc == 'Registration successful'
flash[:notice] = "Registration successful"
redirect_to "/"
else
doc.xpath('/status/error').each do |link|
@err = link.content
end
flash[:notice] = @err
render "new"
end
end
case res
when Net::HTTPSuccess, Net::HTTPRedirection
@doc = Nokogiri::XML(data)
@doc.xpath('/status/success').each do |oop|
@ee = oop.content
end
if @ee.nil?
@doc.xpath('/status/error').each do |link|
@status = link.content
end
flash[:notice] = @status
render "new"
else
flash[:notice] = @ee
redirect_to "/"
end
end