2012-02-03 14 views
0

apiでは、params内のリクエストデータでurlを押してXml応答を生成しています。 HTMLコンテンツとタグを持つフィールドがいくつか含まれています。コンテンツはDBに正しく保存されていますが、レスポンスが生成されるとタグがエンコードされます。このタグは解析中にフィールドをスキップする必要があるため発生します。私は解析する際に特定のフィールドをスキップするためにCDATAをどのように実装することができるのかを知りたいと思います。CDATAを使用したxml応答用のparams内のhtmlデータの解析

def generate_mobile_api_success_response(status_code, format, request_id, content = nil) 
    format_type_method, options_hash, content_type = get_format_method(format) 

    data = { "request_id" => request_id, "status" => status_code, "message" => status_message(status_code)} 
    data["data"] = content unless content.blank? 
    data = generate_data_format(format, data) 

    resp = [status_code, { "Content-Type" => content_type , "request_id" => request_id}, data.send(format_type_method, options_hash)] 
    generate_active_controller_response_format(resp) 
    resp 
end 

渡されるコンテンツはparamsハッシュであり、フォーマットはxmlです。私はit.Detailed descriptionタグは、私は確かに必要であれば、いくつかの余分なコードを投稿したいと思い符号化されたデータ

[201, {"request_id"=>"b425bce0-307d-012f-3e68-042b2b8686e6", "Content-Type"=>"application/xml"}, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<response>\n <data>\n <fine_print_line_3>line 3</fine_print_line_3>\n <available_start_date>2012-02-02T06:00:00+05:30</available_start_date>\n <status>inactive</status>\n <highlight_line_2>gfgf</highlight_line_2>\n <original_price>50.00</original_price>\n <category_id>bc210bb0-52b7-012e-8896-12313b077c61</category_id>\n <available_end_date>2012-03-25T00:00:00+05:30</available_end_date>\n <expiry_date>2012-08-25T00:00:00+05:30</expiry_date>\n <highlight_line_3></highlight_line_3>\n <product_service>food</product_service>\n <created_at>2012-02-03T15:43:56+05:30</created_at>\n <detailed_description>&lt;b&gt;this is the testing detailed&lt;/b&gt; </detailed_description>... 

が含まれている印刷しようとしたときRESPには、以下のデータが含まれています。

+0

私は、示唆されたansの大部分を見回しましたが、私のためにうまく動作しませんでした:( – Bijendra

答えて

0

あなたのデータはXMLであり、これらのフィールドの内容を知りたいと思いますか?

使用鋸山:

xml = data.send(format_type_method, options_hash) 
doc = Nokogiri::XML(xml) 
start_date = doc.xpath("//available_start_date").content 

p start_date #=> "2012-02-02T06:00:00+05:30" 

あなたはあなたが欲しいものは何でもできる変数で、あなたのフィールドを持っていたら。