473,509 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SoapClient Escaping XML Tags

7 New Member
Hey guys,
I recently lost hours to the PHP 5.2.1 SoapClient when trying to use a remote webservice. There are two methods I have to use, the first one worked like a charm and the second one has me fuming mad. The two methods are "GetSessionToken" which expects two strings, and "SetProjectData" which expects XML wrapped in a CDATA tag.

My problem is that the XML I pass to SetProjectData is being escaped by the PHP SoapClient and I don't know how to turn this off. The XML characters < > and & are being escaped to &lt; &gt; and &amp; -- I need this to stop! It's not documented on php.net anywhere and I don't know where to turn.

Sample:
Expand|Select|Wrap|Line Numbers
  1. $client = new SoapClient('my.wsdl',array('tracing'=>1));
  2.  
  3. $getSessionTokenParams = array('username'=>$username,'password'=>$password); //When passed to the webservice in the next line, this creates two XML tags, <username> and <password> with the appropriate values inside
  4.  
  5. $client->GetSessionToken($getSessionTokenParams); //Runs properly, gives me a session token.
  6.  
  7. $setProjectDataPayload = "<![CDATA[<data><projectinfo>details</projectinfo></data>]]>"; //Webservice expects inside XML to be wrapped in CDATA
  8.  
  9. $setProjectDataParam = array("sdsXML" => $setProjectDataPayload); //Webservice expects CDATA to be inside one sdsXML tag
  10.  
  11. //Here's where it breaks:
  12. $client->SetProjectData($setProjectDataParam); //Remote webservice fails with "not properly formated XML" error
  13. echo $client->__getLastRequest(); //Output the Webservice request and what do I find?  $setProjectDataPayload has all of the XML tags <, > and & have all been escaped and I didn't do it.  The sdsXML tag itself is not escaped, only its contents.  Why is this happening?  Where is this documented?
  14.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

Most importantly: How the heck do I turn "feature" off? I just want it to pass the literal data I send to it, please no chracter escaping!
Jun 8 '07 #1
4 14066
bucabay
18 New Member
Hey guys,
I recently lost hours to the PHP 5.2.1 SoapClient when trying to use a remote webservice. There are two methods I have to use, the first one worked like a charm and the second one has me fuming mad. The two methods are "GetSessionToken" which expects two strings, and "SetProjectData" which expects XML wrapped in a CDATA tag.

My problem is that the XML I pass to SetProjectData is being escaped by the PHP SoapClient and I don't know how to turn this off. The XML characters < > and & are being escaped to &lt; &gt; and &amp; -- I need this to stop! It's not documented on php.net anywhere and I don't know where to turn.

Sample:
Expand|Select|Wrap|Line Numbers
  1. $client = new SoapClient('my.wsdl',array('tracing'=>1));
  2.  
  3. $getSessionTokenParams = array('username'=>$username,'password'=>$password); //When passed to the webservice in the next line, this creates two XML tags, <username> and <password> with the appropriate values inside
  4.  
  5. $client->GetSessionToken($getSessionTokenParams); //Runs properly, gives me a session token.
  6.  
  7. $setProjectDataPayload = "<![CDATA[<data><projectinfo>details</projectinfo></data>]]>"; //Webservice expects inside XML to be wrapped in CDATA
  8.  
  9. $setProjectDataParam = array("sdsXML" => $setProjectDataPayload); //Webservice expects CDATA to be inside one sdsXML tag
  10.  
  11. //Here's where it breaks:
  12. $client->SetProjectData($setProjectDataParam); //Remote webservice fails with "not properly formated XML" error
  13. echo $client->__getLastRequest(); //Output the Webservice request and what do I find?  $setProjectDataPayload has all of the XML tags <, > and & have all been escaped and I didn't do it.  The sdsXML tag itself is not escaped, only its contents.  Why is this happening?  Where is this documented?
  14.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

Most importantly: How the heck do I turn "feature" off? I just want it to pass the literal data I send to it, please no chracter escaping!
I haven't used PHP's built in SOAP client so I can't help you with how to turn the escaping off.. however, if you remove the <![CDATA[ tags it would be equivalent to the actual CDATA wrapped in <![CDATA[.
It would work unless the soap server actually needs the <![CDATA[ tags?
Jun 9 '07 #2
brandonkirsch
7 New Member
The server expects the CDATA tags for one, and more importantly the XML I send inside of CDATA is being escaped anyways: Even if I remove the CDATA text, I still end up with &lt;myxmltag&gt; and the remote call fails.

I can't be the first person to use CDATA with PHP's SoapClient. I just can't figure out why in the world my data is being escaped.

Edit** In my original code, I pass:
Expand|Select|Wrap|Line Numbers
  1. array('tracing'=>1)
in the SoapClient constructor but the proper value is actually
Expand|Select|Wrap|Line Numbers
  1. array('trace'=>1)
Jun 10 '07 #3
keeby
1 New Member
I just wrote a simple class to do it.

Signed up to help you out, so, I hope it does!

Expand|Select|Wrap|Line Numbers
  1. class XMLClient extends SoapClient {
  2.  
  3.     public function XMLClient($wsdl) {
  4.         try {
  5.           parent::__construct($wsdl);
  6.         } catch (SoapFault $exception) {
  7.             $this->error = $exception;
  8.         }
  9.     }
  10.  
  11.     public function __doRequest($request, $location, $action, $version) {
  12.         $request = str_replace("&lt;", "<", $request);
  13.         $request = str_replace("&gt;", ">", $request);
  14.         print "Request - " . $request;
  15.         return parent::__doRequest($request, $location, $action, $version );
  16.     }
  17. }
  18.  
Usage:

Expand|Select|Wrap|Line Numbers
  1. $x = XMLClient("my.wsdl");
  2. $x->getSomeBooks("<some><xml><content></content></xml></some>");
  3.  
Oct 30 '07 #4
Roel Veldhuizen
1 New Member
I had the same problem. After some trail and error. If found a solution. You could use SoapVar with XSD_ANYXML.

Expand|Select|Wrap|Line Numbers
  1. new SoapVar("<param2><![CDATA[<html><body>Some content</body></html>]]> </param2>", XSD_ANYXML)
Blogged it over here: http://bit.ly/e8oPrt
Mar 24 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1946
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records....
5
1718
by: Jim Bancroft | last post by:
Hi everyone, I receive XML documents which sometimes have HTML in the element content. When performing XSL transformations the HTML text is escaped, which affects us when we eventually display...
18
10429
by: Robert Bowen | last post by:
Hello peeplez. I have an odd problem. When I put the ANSI symbol for "less than" ("<"), the word STRONG and then the ANSI symbol for "greater than" (">") in my web page, followed by some text, then...
8
6000
by: Kathleen Dollard | last post by:
Hi, Oleg's answer about attribute value templates led me to look back at a different problem, and wonder if someone else had solved it. I want to output an ASP.NET page. Thus I need to output...
1
6023
by: Yolande | last post by:
Hi there, I try to use MSSOAPLib.soapClient to get the XML data produced by our web services. I have a web method call ReportExec(strID, strRequest). It takes two string arguments and returns a ...
3
7329
by: Andy | last post by:
Hi, I'm trying to render tabular data in an HTML document using XSL to transform XML data into an HTML table. Some of the tabular data appears as droplists (implemented by the HTML Select and...
1
1766
by: macupryk | last post by:
soapclient. need to extract information in php from a webservice that was built in C# asp.net 2.0 I am new to php. Can someone help me with the code below. I would like to learn how to manipulate...
11
21538
by: brandonkirsch | last post by:
Hey guys, I've posted a question on here before but I don't think I was very direct about the problem so I'll state it in a new way: How do I send CDATA to a webservice using the PHP SoapClient? ...
1
2342
by: jamieg99 | last post by:
Hello, I've got an object that's being converted into SAXSource and then converted into a pdf with FOP. Some of the data however is in HTML format inside the xml tags and is being escaped (&gt;, etc)...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.