Connecting Tech Pros Worldwide Help | Site Map

how to assign attributes to paramater in php for nusoap client

Newbie
 
Join Date: Jun 2007
Location: cheshire uk
Posts: 2
#1: Jun 20 '07
Hi all

I'm having trouble assigning an attribute to a namespace using nusoap/php when creating a new soapclient. I can get the soapclient to assign the parameters correctly but can't assign an attribute to any namespaces. The code below is from the actual soap request and i need to assign the 'ApplicantID' from the soapclient to the Applicant parameter for each new applicant, then have nested arrays within various arrays.

Expand|Select|Wrap|Line Numbers
  1. <Applicant ApplicantID="1">
  2. <Title>Miss</Title>
  3. <Forename>Tessa</Forename>
  4. <Secondname>Jane</Secondname>
  5. <Surname>Smith</Surname>
  6. <DOB>1966-12-29</DOB>
  7. <TelephoneHome>01942408669</TelephoneHome>
  8. <TelephoneWork>01942724915</TelephoneWork>
  9. </Applicant>
I've set up all the arrays as follows, but was wondering how to assign the 'ApplicantID' to the 'Applicant' array in the soapclient.

[PHP]$header = array('userId' => 'Ivuser', 'password' => 'Ivpa55word');
$loandetail = array('Loan' => '5000', 'Term' => '24');
$Applicant =
$result = $client->call('sendv1', array('header' => $header), array('loandetail' => $loandetail));[/PHP]

i'm a total nusoap novice so sorry if i haven't given enough information. Your help would be much appreciated.
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Jun 20 '07

re: how to assign attributes to paramater in php for nusoap client


Heya, johnners. Welcome to TSDN!

It sounds like you're looking for an XML parser. PHP's got a couple of those....
Newbie
 
Join Date: Jun 2007
Location: cheshire uk
Posts: 2
#3: Jun 20 '07

re: how to assign attributes to paramater in php for nusoap client


thanks for the reply - we're using a shared windows server which is having a few problems with .net applications and ssl certificates, hence we decided to re-write the application using php to access a webservice using a soap client. However we cannot have access to the php.ini or full root of the server to make any changes to the configuration of php. Using php4 so we thought we'd give nusoap a go to create the soap client. Just need to know how to code the array for the 'Applicant' in the soap client as the namespace has the 'ApplicantID' attribute. Having trouble getting the soapclient to pass on the 'ApplicantID' as part of the namespace.

Not sure if i'm explaining it very clearly!
Newbie
 
Join Date: Jul 2007
Posts: 1
#4: Jul 20 '07

re: how to assign attributes to paramater in php for nusoap client


I too am needing to know how to set a node attribute. I need to set an attribute to false to indicate a testing environment versus a live environment, and cannot test the XML call without that attribute which is required by the webservice server...

Anyone? Anyone? Bueller?

AG


Quote:

Originally Posted by johnners

Hi all

I'm having trouble assigning an attribute to a namespace using nusoap/php when creating a new soapclient. I can get the soapclient to assign the parameters correctly but can't assign an attribute to any namespaces. The code below is from the actual soap request and i need to assign the 'ApplicantID' from the soapclient to the Applicant parameter for each new applicant, then have nested arrays within various arrays.

Expand|Select|Wrap|Line Numbers
  1. <Applicant ApplicantID="1">
  2. <Title>Miss</Title>
  3. <Forename>Tessa</Forename>
  4. <Secondname>Jane</Secondname>
  5. <Surname>Smith</Surname>
  6. <DOB>1966-12-29</DOB>
  7. <TelephoneHome>01942408669</TelephoneHome>
  8. <TelephoneWork>01942724915</TelephoneWork>
  9. </Applicant>
I've set up all the arrays as follows, but was wondering how to assign the 'ApplicantID' to the 'Applicant' array in the soapclient.

[PHP]$header = array('userId' => 'Ivuser', 'password' => 'Ivpa55word');
$loandetail = array('Loan' => '5000', 'Term' => '24');
$Applicant =
$result = $client->call('sendv1', array('header' => $header), array('loandetail' => $loandetail));[/PHP]

i'm a total nusoap novice so sorry if i haven't given enough information. Your help would be much appreciated.

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#5: Jul 20 '07

re: how to assign attributes to paramater in php for nusoap client


I don't generally use XML parsers to generate XML, to be honest. What I do is create an XML template and then create tags where I'd want stuff to go.

Expand|Select|Wrap|Line Numbers
  1. <Applicant ApplicantID="[::ApplicantID::]">
  2. <Title>[::Title::]</Title>
  3. <Forename>[::Forename::]</Forename>
  4. <Secondname>[::Secondname::]</Secondname>
  5. <Surname>[::Surname::]</Surname>
  6. <DOB>[::DOB::]</DOB>
  7. <TelephoneHome>[::TelephoneHome::]</TelephoneHome>
  8. <TelephoneWork>[::TelephoneWork::]</TelephoneWork>
  9. </Applicant>
  10.  
Then load up your template, create an array of content:
Expand|Select|Wrap|Line Numbers
  1. $content = array(
  2.     '[::ApplicantID::]' => $applicantID,
  3.     '[::Title::]'       => $title,
  4.     .
  5.     .
  6.     .
  7. );
  8.  
And then run a fancy str_replace():
Expand|Select|Wrap|Line Numbers
  1. $xml = str_replace(array_keys($content), array_values($content), $template);
  2.  
Reply