58

In SOAP-UI I am making a request to a web service like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xxx="http://xxx.call/">
   <soapenv:Header/>
   <soapenv:Body>
      <cotf:call_XXX>
         <!--Optional:-->
         <arg0>
            <!--Optional:-->
            <parameter1>some text</parameter1>
            <!--Optional:-->
            <parameter2>XML string</parameter1>
         </arg0>
      </cotf:call_XXX>
   </soapenv:Body>
</soapenv:Envelope>

What I would like to know is how I can pass an XML string on parameter 2 since if I put the XML string directly it assumes the XML string nodes as request parameters....

Thanks

RedEagle
  • 4,418
  • 9
  • 41
  • 64

3 Answers3

133

Either encode the needed XML entities or use CDATA.

<arg0>
    <!--Optional:-->
    <parameter1>&lt;test>like this&lt;/test></parameter1>
    <!--Optional:-->
    <parameter2><![CDATA[<test>or like this</test>]]></parameter2>
 </arg0>
Alin Purcaru
  • 43,655
  • 12
  • 77
  • 90
  • In the first example why not encoding `>` with `>`? Is it okay to encode both `<` and `>`? – ForguesR Nov 16 '16 at 19:38
  • 1
    @ForguesR Encoding `>` is needed only in some extreme situations. For safety it may be ok to just encode it always when it's part of content. It's possible that in the past some XML validators/parsers didn't recognize `>` as a valid XML entity, but I may be talking rubbish. https://www.w3.org/TR/1998/REC-xml-19980210 – Alin Purcaru Nov 17 '16 at 01:05
  • Is there anything special needed on the receiving end if we use the CDATA method, or will it be translated correctly with no help from the service? – Bpainter Nov 30 '16 at 22:09
  • @Bpainter CDATA is part of the XML specs. If you have a decent XML parser, then you don't need to do anything. – Alin Purcaru Dec 07 '16 at 08:04
1

NOTE: This one is just an alternative for the previous provided .NET framework 3.5 and above

You can send it as raw xml

<test>or like this</test>

If you declare the paramater2 as XElement data type

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Arjun Shetty
  • 1,575
  • 1
  • 15
  • 36
  • Any idea how to specify in a raw request (i.e. through Fiddler or SoapUi or Wizdler) that `parameter2` is XElement data type? – drzaus Jul 19 '17 at 20:49
0

To send CDATA in a request object use the SoapObject.setInnerText("..."); method.

Randnum
  • 1,360
  • 4
  • 32
  • 48