When I was doing a senior project with my friends before graduating, I faced a lot of problems that had never found in classes. One problem that I feel like we had no way to solve it is about an XML input parameter of SOAP request. Why? The structure of SOAP request is an XML document as the figure below. As such, when it’s being sent to desired web service, they will treat the SOAP request as an XML via the XML parser to extract the parameter for further uses inside the web services.

<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
     <SendCustomer xmlns="http://namespace">
       <customer_information>
	       <?xml version="1.0" encoding="utf-8" ?>
		     <customer>
				<id_card>123</id_card>
				<fname>abc</fname>
	         </customer>
	  </customer_information>
     </SendCustomer>
  </soap:Body>
</soap:Envelope>

It would be no problem, If the parameter inside, which is

<?xml version="1.0" encoding="utf-8" ?>
  <customer>
    <id_card>123</id_card>
    <fname>abc</fname>
  </customer>

of this SOAP request, is just an ordinary “string”. The problem is coming because the XML parser will extract the parameter inside as other XML elements by observing from < and & to understand that it’s element and entity of XML document respectively. It will, then, result to not being the structure of SOAP request anymore because of not just a simple string.
Anyway, if there is a problem, there will be solutions. The problem could be coped by telling the XML parser that I want you to treat the parameter as a string instead of treating it as an XML document. The way to tell it like that is to add

<![CDATA[ ...XMLDOC... ]]>

to the input string parameter as the figure below.

<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
     <SendCustomer xmlns="http://namespace">
       <customer_information>
		<![CDATA[<?xml version="1.0" encoding="utf-8" ?>
			<customer>
				<id_card>123</id_card>
				<fname>abc</fname>
			</customer>]]>
		</customer_information>
     </SendCustomer>
  </soap:Body>
</soap:Envelope>

CDATA is a section on an XML document that is only a character data and not be parsed by the XML parser. Then, it will treat the whole xml imput parameter as a string. Finally, the web services can interpret it.

Reference: http://www.w3schools.com/xml/xml_cdata.asp

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine