NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
associative array as argument


Joined: 22 May 2006
Posts: 2
Reply with quote
hi all,
I'm not beeing able to represent some xml data as an associative array in PHP to pass to the soapclient call function. Any idea will be appreciated.

This is the data that I need to represent as an associative array:
Code:
<phonebook>
   <person>
      <name></name>   
      <phone></phone>
   </person>
   <person>
      <name></name>   
      <phone></phone>
   </person>
   ...
</phonebook>


Thanks in advance.
View user's profileFind all posts by eriderSend private message


Joined: 07 Mar 2006
Posts: 22
Reply with quote
I'm probably in very deep water here and probably don't know what I'm talking about seeing as I'm not exactly sure how the SOAP client works, but the following outputs what you are requesting. If nothing else it may give some hints in the right direction of what you need....hope it helps

Code:
<?php

$phonebook = array(array('stan' => '344 3980'), array('mike' => '976 5620'), array('george' => '754 0032'));

print '<phonebook>';
for($i = 0; $i < count($phonebook); $i++)
{
   print "\r\n\t";
   print '<person>';
   print "\r\n\t\t";
   while(list($key, $value) = each($phonebook[$i]))
   {
      print '<name>' . $key . '</name>';
      print "\r\n\t\t";
      print '<phone>' . $value . '</phone>';
   }
   print "\r\n\t";
   print '</person>';
}
print "\r\n";
print '</phonebook>';

?>
View user's profileFind all posts by Joe BelmaatiSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
as far as I understood erider talked about the quite the opposite way, he has XML and want to pass it to nusoap using array.

it's not that hard if you try to prefix your xml with standard xml header <?xml blah blah blah?> and call expat parser to parse it. There are many examples on how to do it: http://www.php.net/manual/en/function.xml-parse.php


Last edited by dmitri on Tue May 23, 2006 11:42 am; edited 1 time in total
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 22 May 2006
Posts: 2
Reply with quote
Thanks for your help!
I followed the link http://ru.php.net/manual/en/function.xml-parse.php looking for some examples
and I could represent the xml text using an object instead of an associative array which is the same for my purpose.
The class is xml_doc, found at
I did something like this:

Code:
$xml = new xml_doc();

$root_tag = $xml->createTag('phonebook');

$person=$xml->createTag('person',array(),'',$root_tag);
$name_tag=$xml->createTag('name',array(),'jose',$person);
$phone_tag=$xml->createTag('phone',array(),'73989028',$person);

$person=$xml->createTag('person',array(),'',$root_tag);
$name_tag=$xml->createTag('name',array(),'luis',$person);
$phone_tag=$xml->createTag('phone',array(),'73982332',$person);

$my_output = $xml->generate();

print htmlspecialchars($my_output);
View user's profileFind all posts by eriderSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
What you posted can be achieved even easier. See http://www.php.net/xml_writer
View user's profileFind all posts by dmitriSend private messageVisit poster's website
associative array as argument
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic