- #response to client
- respond_to do |wants|
- wants.html { redirect_to(person_list_url) }
- wants.js
- wants.xml { render :xml => @person.to_xml(:include => @company) }
- end
- #获取params里传来的xml数据:
- #get data from parameters
- channel_info_hash = Hash.from_xml(params[:id])
- #post datas to the server
- #response = Net::HTTP.post_form(
- URI.parse('http://192.168.5.189:3001/productcenter/sku/updatefrominventory'), {'product'=>re.to_xml()}
- )
- #product 为在上文中处理好的 产品 hash 表
-
- path = '/productcenter/admin/receive_channelInfo/'
- response = Net::HTTP.post_form(
- URI.parse('http://'+PRODUCTCENTER_SITE+':'+PRODUCTCENTER_PORT+path),
- {'product'=>re.to_xml()}
- )
ruby 代码
- 注:需发引入 require 'rexml/document'
- 在命令行可以 在代码前面用include REXML 载入命令空间。
- 但在类里面还尚未找到 怎样使用include REXML方法。
- 故下面的代码中需要使用REXML::Document.new()来载入Document模块类。
- #skuImages xml
- skuImages_xml= @channel.skuid_imageAttr_into_hash.to_xml
- skuImg_doc = REXML::Document.new(skuImages_xml)
- element_skuImages = skuImg_doc.root.elements['skuImages']
- #channel xml
- channel_xml = REXML::Document.new(@channel.to_xml)
- channel_doc = channel_xml.root
- # skuImages join into channel
- channel_doc.elements << element_skuImages
- respond_to do |accepts|
- accepts.html
- accepts.xml { render :xml => channel_xml.to_s}
- end