使用SOAP

首先,安装soap:

 

gem install soap4r

 

示例代码:

 

    require 'soap/wsdlDriver'
    require "rexml/document"

    wsdl = "http://h-invitational.jp/hinv/hws/soap_acc2hit.php?wsdl"
    serv = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    #调用服务方法
    result = serv.acc2hit("BC053657")
    xml = REXML::Document.new(result)
    #服务返回的结果如下:
    #   <?xml version='1.0' encoding='UTF-8'?>
    #   <H-Inv>
    #   <H-INVITATIONAL-ID>HIT000053961</H-INVITATIONAL-ID>
    #   </H-Inv>
    #获取xml的版本号
    puts xml.version()  # => 1.0
    #解析xml
    xml.elements.each("H-Inv/H-INVITATIONAL-ID") do |element|
      puts element.text  # => HIT000053961
    end

 

你可能感兴趣的:(xml,PHP,SOAP)