Solved

How do I send CDATA with php/nusoap?

Posted on 2011-02-21
3
2,438 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now