0

Rails Webサービスに次のメッセージを送信しています:

xmlPostData = "<message>
                   <message-text>" + MESSAGE_WITH_XML  + "</message-text>
                   <name>" + subject + "</name>
                   <f1>" + toPhone + "</f1>
                   <f2>" + fromPhone + "</f2>
               </message>";

問題は、フィールドに XML データを含むテキストが含まれていることです。これは回避策ですが、その xml をデータベースに送信してそこから取得できるようにする必要があります。

Rails による xml の検証と json 形式への置換を停止できますか? これはそれがどのように見えるかです:

    --- !map:HashWithIndifferentAccess 
smil: !map:HashWithIndifferentAccess 
  head: !map:HashWithIndifferentAccess 
    layout: !map:HashWithIndifferentAccess 
      root_layout: !map:HashWithIndifferentAccess 
        height: &quot;600&quot;
        background_color: white
        width: &quot;800&quot;
      type: text/smil-basic-layout
  body: !map:HashWithIndifferentAccess 
    par: !map:HashWithIndifferentAccess 
      text: !map:HashWithIndifferentAccess 
        left: &quot;33&quot;
        begin: &quot;33&quot;
        dur: &quot;33&quot;
        val: 34343434343434343aaaaaaa
        height: &quot;33&quot;
        width: &quot;33&quot;
        top: &quot;33&quot;

これは、Rails Web サービスの ruby​​ メソッドです。

# POST /messages
  # POST /messages.xml
  def create
    @message = Message.new(params[:message])

    respond_to do |format|
      if @message.save
        flash[:notice] = 'Message was successfully created.'
        format.html { redirect_to(@message) }
        format.xml  { render :xml => @message, :status => :created, :location => @message }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @message.errors, :status => :unprocessable_entity }
      end
    end
  end

回避策ですが、今のところこれは機能する必要があります...

4

1 に答える 1

1

任意のテキストを埋め込む必要がある場合は、CDATA を使用する必要があります。文字列]]>が MESSAGE_WITH_XML に含まれていないことを確認してください。

xmlPostData = "<message>
                   <message-text><![CDATA[" + MESSAGE_WITH_XML  + "]]></message-text>
                   <name>" + subject + "</name>
                   <f1>" + toPhone + "</f1>
                   <f2>" + fromPhone + "</f2>
               </message>";
于 2010-04-20T00:54:26.033 に答える