ADVICE: XML DOC CREATION & PASSING WITH PEAR

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MentalWealth
Forum Newbie
Posts: 19
Joined: Thu Apr 13, 2006 5:20 am

ADVICE: XML DOC CREATION & PASSING WITH PEAR

Post by MentalWealth »

Hi all, a little advice please.

I have created a PHP PEAR SOAP web service via Soap_WSDL method. This service allows property searchers or registered property advertisers to:

-log in
-view account info
-update account info
-upload property details
-search for property

at the minute this service sends/receives data via soap envelopes, data just encased in SOAP envs etc.
i make use of a MYSQL database, and everything seems to work fine.

i would like to change the data passing between client and server to XML document format, for cross OS / Systems compatibility. PEAR packages i have been viewing are:

xml_tree
xml_rpc
xml_serializer
xml_beautifier


could someone advise me on the best option to take, given the state of my service at this point? (eg easiest method to integrate). What is the easiest way i can construct and send xml docs between client and server? am i looking at the right packages?

i have been viewing XML_RPC, and creating examples..........this package doesnt SEEM like the right one, as the example i used creates an xml_rpc client/server etc to facilitate the data sending/receiving. I already have my client/server defined and working, passing SOAP envelopes.

what i would like to do is create xml docs on the client side, use them to send my data to the server, the server would then decode the doc, perform actions, and create a response in XML doc format, sending it back to the client, which again would decode for the user.

any help much appreciated.....thanks in advance!
MentalWealth
Forum Newbie
Posts: 19
Joined: Thu Apr 13, 2006 5:20 am

Post by MentalWealth »

I think i have it, i am converting all my array data passing(client->server, vice versa) to associative arrays, to help tag naming convention in XML docs, and also for the client to better understand the data elements they are recieving (instead of 0,1,2 etc). Then i will be using the xml_serializer class to create/decode my xml docs on both sides(client/server).

the only 'fog' at the minute is regarding the actual passing of the doc created, using my SOAP_WSDL client /server setup.......any info on this anyone? should it be straight forward?


guess i will find out..........but not till tomorrow. time for sleep!

MW 8O
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

k firstly its parsing not passing in this sense
secondly try the xmldom functions
MentalWealth
Forum Newbie
Posts: 19
Joined: Thu Apr 13, 2006 5:20 am

Post by MentalWealth »

thanks for the reply. I have read the extension page, and have a couple of questions about it.........


first, WHY exactly do i need this function? i can already create and decode XML documents perfectly well using packages i am looking at. And second, this php4 xml_dom func is not going to be implemented into PHP5.......what if my web host upgrades? or the clients webhost? we will need to search for a php4 implementation to keep it running.....? please correct me if i am wrong.


at the minute i plan to use serialiser, pear::tree etc..............i still have the 'fog' regarding passing the actual docs. With the XML doc being contained in a object variable, i assume i can just send the XML_DOC object.

will find out soon..........


cheers.

M
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

first, WHY exactly do i need this function?
I can't comment on packages I've not yet needed to use them personally I would always prefer any PHP extension that appears in the PHP manual over a package and also this one looks really nice especially if you are famililar with the DOM.
And second, this php4 xml_dom func is not going to be implemented into PHP5.......
Really? I find that very disappointing where does it say that? Possibly there is a better alternative that will be built into PHP 5 hmmmm.
what if my web host upgrades? or the clients webhost? we will need to search for a php4 implementation to keep it running.....? please correct me if i am wrong.
Regards to the issues of hosting upgrades I would change your hosting to something where you have full control such as VPS (virtual private server) seriously. If you are on a shared hosting account or one where you cannot make configuration changes you will run in to problems every time you time and do something that rudimentory and you sound like the kind of person would like to do pretty advanced stuff. Not to mention security on shared host is bad because its very difficult to prevent other hosting on the same server as you reading your scripts with fopen() and stuff like that.
send xml docs between client and server?
So you are going to be creating XML from form data using JavaScript? This is what we call AJAX. I'm actually not very familiar with XML so i'm probably the wrong person to be advising you. Personally I would buy a book on AJAX.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

oh and look at the xml parser functions these are built into php core
MentalWealth
Forum Newbie
Posts: 19
Joined: Thu Apr 13, 2006 5:20 am

Post by MentalWealth »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


thanks for the reply. I will look into some of the things you mentioned. especially VPS....



I was able to integrate the PEAR serializer/unserializer functions into my web service quite easily, and now all data passed is via xml docs.    phew! 
one problem i had was with syntax at first, and the job was made easier via associative array passing.


[b]couple of things:[/b]

1:
one array in paticular that i would like to get back from the server (search results - prop ref list that match criteria) seems to appear buried in another element. With these results, i am parsing the mysql results rows, and collating the prop refs to another array, then i pass this to be serialised at the server, and sent to be  unserialised at the client. The array seems to be 1 level deeper than it should be. There should be a 'responsecode' element, and a 'message' element. The message element holds either a string, or an array of values. The message is coming back with a 'value' tag, and the array data is inside that tag:

eg:  message -> value - > data array
when i want:   message -> data array

the 'value' tag is my default tag name provided to the serializer. But why the tag appears i have no idea. I am returning an array, just like all other server calls. The only difference i am doing with this array in code is collating the search results from rows in a result set into another array. This is making it hard for me to get at the data, because when i try to detect a 'value' tag with an array in it, inside the 'message', all other returned arrays start acting weird,  strings returned are recognised as arrays, and thus chars are printed instead of a string. PHP does not seem to differentiate properly between strings and arrays. (i know strings are array of chars).

hope this is clear! 


2:
when i search for property (same task as above(1)), it sends back a list of property reference numbers. This search seems to be limited to 54 search results(i know this from the print_r).......does anyone know if soap data exchange is limited to a certain size?


3:
I need to be able to connect with my soap server via asp.net and j2ee clients. This should be straight forward, as they create a server out of my WSDL doc (in theory), which tells them what they can/cant do etc.
unfortunately my wsdl doc seems incomplete to what i have read about them, but my client will still error if i try to use an undisclosed function, or if argument counts for functions are not correct.  How does it know? and will other clients 'know'. 

 From what i have read, all funcs etc should be listed in here? along with data types they can recieve, and data types that will be returned.....

heres my WSDL:

[syntax="xml"]
<?xml version="1.0" ?> 
- <definitions name="NNEPC" targetNamespace="urn:NNEPC" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:NNEPC" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types xmlns="http://schemas.xmlsoap.org/wsdl/" /> 
  <portType name="NNEPCPort" /> 
- <binding name="NNEPCBinding" type="tns:NNEPCPort">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> 
  </binding>
- <service name="NNEPCService">
  <documentation /> 
- <port name="NNEPCPort" binding="tns:NNEPCBinding">
  <soap:address location="[b]address would go here for server file - sry no test runs [/b]" /> 
  </port>
  </service>
  </definitions>

thanks inadvance MW


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

MentalWealth you may find a forum dedicated to XML questions more suited to your needs.
eg: message -> value - > data array
when i want: message -> data array
try:

Code: Select all

// example data
$message = array(
   'value' => array(1,2,3,4)
);
// patch
$message = $message['value'];
I wonder though if the serializer is doing this for a reason and 'value' index may be relyed upon in later code.
arrays start acting weird, strings returned are recognised as arrays, and thus chars are printed instead of a string. PHP does not seem to differentiate properly between strings and arrays. (i know strings are array of chars).
yes i'm familiar with that problem this was one of the reasons way the PHP team posed change string offset syntax from [index] to {index} but they scrapped that idea because it was alien to everyone from a C background.

So yes you need to be aware that:

Code: Select all

$foo = 'stuff';
$foo[0]; // outputs 's'
$foo = array(1,2,3);
$foo[0]; // outputs 1
You can use is_array and is_string checks if you like but this isn't addressing the problem. I'm afraid this is something only you can likely fix. One thing I would say however is that if the contents and structure of assoc arrays starts to become too difficult to store in your head all at once (something i've experienced) you need to start moving into OO code. Classes are great for making your data structures ridgid as you can't dynamically add or remove properties from an object.
when i search for property (same task as above(1)), it sends back a list of property reference numbers. This search seems to be limited to 54 search results(i know this from the print_r).......does anyone know if soap data exchange is limited to a certain size?
no idea. Personally I would probably throw out the idea that the output size is capped, i can't see any reason why this would be imposed on a system so its probably your mistake somewhere.
3:
I need to be able to connect with my soap server via asp.net and j2ee clients. This should be straight forward, as they create a server out of my WSDL doc (in theory), which tells them what they can/cant do etc.
unfortunately my wsdl doc...
My total knowledge of WSDL is what is does. You might want to read up on "Web Services". But i'm not sure here.
MentalWealth
Forum Newbie
Posts: 19
Joined: Thu Apr 13, 2006 5:20 am

still need help...anyone?

Post by MentalWealth »

thanks.....
MentalWealth you may find a forum dedicated to XML questions more suited to your needs.
i think PHP forums would be better suited, i am having no major probs with xml, just some little stuff.


i did try your php example before, it doesnt work. It seems that although no 'value' tag is in the other arrays, calling 'value' will ALSO be relevant to those arrays....ie, it gets data from them, messing up my 'if else print response engine', even though no value tag is within them!
I wonder though if the serializer is doing this for a reason and 'value' index may be relyed upon in later code.
i dont think so....when i have the data, all i am doing is unserialising it, so the value tag would dissappear for good from that array, the data is not used for subsequent requests/responses at all. I believe this is definitely to do with me building an array, from results set rows. All others arrays pass fine, except this one. Like i said, the only difference is that i am constructing an array to be returned, not just returning a row from the results set obtained.


you need to start moving into OO code. Classes are great for making your data structures ridgid as you can't dynamically add or remove properties from an object.
i do use OO code, and am very familiar with PHP, been working with it for over two years now. This is just my first attempts at web applications and soap.


MW
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Well I'm confused.
i do use OO code, and am very familiar with PHP, been working with it for over two years now. This is just my first attempts at web applications and soap.
Well I'm I've only started programming with OO heavily very recently so your level of experise may be greater than my own and I've basically no experience with SOAP. Sorry I can't help you anymore.
MentalWealth
Forum Newbie
Posts: 19
Joined: Thu Apr 13, 2006 5:20 am

Post by MentalWealth »

thought id post my "response engine" needed to print out arrays, strings AND the value array! lol

not good, should really get rid of value tag.........but it wont go away!
this is the only way i could print out all arrays.......the order was important (string,array,value array).....

Code: Select all

$xml_data = $unserializer->getUnserializedData();// get the response data
$responsecode=$xml_data['responsecode'];//get responsecode
$message=$xml_data['message'];//get message data

echo $responsecode;
if(is_string($message)){//check for single values or array of values for output
	echo $message;
}else if((is_array($message))&&(!isset($message['value']))){
	$labels=array_keys($message);
	for($d=0;$d<count($message);$d++){
		echo $message[$labels[$d]];
	}
}else{
	$message=$message['value'];
	$labels=array_keys($message);
	for($d=0;$d<count($message);$d++){
		echo $message[$labels[$d]];
	}
}
hope this helps someone, even if only a workaround



so now all i have to sort is the WSDL, before i knock up clients in other languages.

anybody any info on PEAR SOAP_SERVER WSDL creation????? as it seems incomplete etc.........

M
MentalWealth
Forum Newbie
Posts: 19
Joined: Thu Apr 13, 2006 5:20 am

Post by MentalWealth »

to generate more complete WSDL documents, for other clients:

http://www.phppatterns.com/docs/develop ... _pear_soap


and to look at creating an ASP.NET client for the service see:

http://www.411asp.net/home/tutorial/spe ... tocol/soap

and

http://msdn.microsoft.com/library/defau ... xpsoap.asp

Code: Select all

$_POST['forumPostCount']+=1;
:wink:
Post Reply