Solved

How do I send CDATA with php/nusoap?

Posted on 2011-02-21
3
2,502 Views
Last Modified: 2012-05-11
Hello,
I've had great success in using nusoap to make calls to another server and parse results... until I tried sending CDATA. It converted all the XML data in my parameter string into entities (see file attached).

Here's a simplified version of what I have. Any thoughts on how to prevent nusoap from messing with my request? :)

<?php
include_once 'nusoap-0.9.5/lib/nusoap.php';
	
$functionName = 'Say';
$request['Text'] = array(
	'SynthString' => '<![CDATA[I am <prosody rate="x-slow">very happy</prosody>]]>',
	'Encoding' => 'UTF-8'
);
$request['VoiceInfo'] = array(
	'Name' => 'Princess',
	'Owner' => 'Cepstral'
);
$request['AudioInfo'] = array(
	'SignalRate' => '16',
	'Format' => 'mp3',
	'DeliveryType' => 'link'
);

$soapClient = new nusoap_client('http://' . 'theserver.com', false);
$result = $soapClient->call($functionName, $request);

//write request to file as seen as an attachment for this post
$myFile = "request.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $soapClient->request;
fwrite($fh, $stringData);
fclose($fh);
?>

Open in new window


Thanks much for the assist in advance! :D
request.xml
0
Comment
Question by:Ultrus
  • 2
3 Comments
 
LVL 10

Author Comment

by:Ultrus
ID: 34946115
OK, I found the magic variable in the nusoap_base class in nusoap.php:

        /**
	 * toggles automatic encoding of special characters as entities
	 * (should always be true, I think)
	 *
	 * @var boolean
	 * @access private
	 */
	var $charencoding = true;

Open in new window


Setting it to false makes my calls work again. Yay! 50% there.

Now, how do I set this without changing the base class file? Since it's a private variable, the following causes an error:
$soapClient = new nusoap_client('http://' . 'theserver.com', false);
$soapClient->$charencoding = false;

Open in new window


:/
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 34957063
I have not done this myself, but you might try -

$soapclient->charencoding = false;

In Object Oriented coding, you do NOT place a second  $  as you did
0
 
LVL 10

Author Closing Comment

by:Ultrus
ID: 34957142
Oh! What a silly mistake I made. It works for me now. Cheers to you for helping me solve the simple things that matter. :)
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question