I'd like to change the tag that is currently 'return' to 'result'. Like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:AuthenticateResponse xmlns:ns1="http://tempuri.org">
<***return***>
<Result xsi:type="xsd:string">OK</Result>
</***return***>
</ns1:AuthenticateResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
(see the value between the ***)
Is this possible? And if so, how?
I've fixed this myself by changing the nusoap.php file (line 4143 like this:
original:
$return_val = $this->serialize_val($this->methodreturn, 'return');
Edited code:
$return_val = $this->serialize_val($this->methodreturn, 'result');
I bet there is a better way of handling this, but this fixes it for me.
Related
I need to make the structure of my XML SOAP request to look like following:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.fines.pl/api/contract">
<SOAP-ENV:Body>
<ns1:newApplicationRequest>
<user_login>XYZ</user_login>
<user_password>XYZ</user_password>
<contract>
<?xml version="1.0" encoding="UTF-8"?>
<sof:Contract xmlns:s="http://www.fines.pl/simple" xmlns:sof="http://www.fines.pl/sof" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fines.pl/sof model.xsd ">
<product>
<prefix>MOP</prefix>
</product>
<participants>
<customers>
<main_borrower>
<personal_data>
<pesel>85050949761</pesel>
<firstname>Anna</firstname>
<lastname>Test</lastname>
<firstname_father></firstname_father>
<firstname_mother></firstname_mother>
<secondname />
<sex>female</sex>
</personal_data>
<contact_data>
<addresses>
<address>
<type>registered</type>
<street_name>Grunwaldzka</street_name>
<block_number>11</block_number>
<flat_number>5</flat_number>
<postal_code>80-100</postal_code>
<city>GdaĆsk</city>
</address>
</addresses>
<phones_mobile>
<phone_mobile>
<type>personal</type>
<number>602200300</number>
</phone_mobile>
</phones_mobile>
</contact_data>
<incomes>
<income>
<type>employment</type>
<main_income>true</main_income>
<fixed_term_contract>false</fixed_term_contract>
<paychecks>
<paycheck>
<amount_net>
<amount>1444.00</amount>
<currency>PLN</currency>
</amount_net>
<type>base</type>
</paycheck>
</paychecks>
</income>
</incomes>
<household_pointer>/households.0</household_pointer>
</main_borrower>
</customers>
</participants>
</sof:Contract></contract></ns1:newApplicationRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
I've set my $params variable to contain user_login and user_password elements with their respective values, but I have no idea how may I set this contract param with required content.
Providing $contract variable with XML code (which i thought may be a workaround) poop the Fatal error: Uncaught SoapFault exception: [xml_structure] String could not be parsed as XML error.
Would be grateful for explaining how could this be done.
You have declared <?xml?> twice , one on the first line and second on the eight. That's the only error I see in the xml side of things.
How do I read this soap response and echo the values of subid and points.
Here is the response
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:zuku">
<SOAP-ENV:Body>
<ns1:showloyaltypointsResponse xmlns:ns1="http://tempuri.org">
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:subpoints[1]">
<item xsi:type="tns:subpoints">
<subid xsi:type="xsd:integer">618341</subid>
<points xsi:type="xsd:string">0</points>
</item>
</return>
</ns1:showloyaltypointsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here is my php code
$result = $client ->call('showloyaltypoints',array("subid" =>$subid,"username" =>"$username", "password" =>"$password"));
echo $client->response;
I found out the solution by converting it to an array first.
https://stackoverflow.com/a/42311833/7042343
How can I edit the xmlns attributes of the <SOAP-ENV:Envelope /> tag?
I have a situation where xmlns:xsi and xmlns:xsd are missing. I'd like to know how to add them back in?
Example:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://fedex.com/ws/track/v12">
<SOAP-ENV:Body>
<ns1:TrackRequest>
...
But I need it be this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://fedex.com/ws/track/v12"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:TrackRequest>
...
I know this is kinda old, but in case someone stumbles upon it...
After fiddling around with SoapVar, this is how it worked for me:
$params[] = new SoapVar('',XSD_ANYXML, '', null, 'Envelope', 'http://www.w3.org/2001/XMLSchema');
$params[] = new SoapVar('',XSD_ANYXML, '', null, 'Envelope', 'http://www.w3.org/2001/XMLSchema-instance');
//you can add more vars here.
//E.g. in my case I also needed $params[] = new SoapVar('<notifications xmlns="http://soap.sforce.com/2005/09/outbound"><Ack>true</Ack></notifications>',XSD_ANYXML); as I was working with salesforces soap.
return new SoapVar($params, XSD_ANYXML);
I am using one payment gateway that return response as xml and I am trying to convert to json buy its not converting. I have tried that simplexamlloadfile , simplexmlsting function and etc.
But its not working.
Code :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns2:SingleVaultResponse xmlns:ns2="http://www.paygate.co.za/PayHOST">
<ns2:LookUpVaultResponse>
<ns2:Status>
<ns2:StatusName>Completed</ns2:StatusName>
<ns2:PayVaultData>
<ns2:name>cardNumber</ns2:name>
<ns2:value>411111xxxxx1111</ns2:value>
</ns2:PayVaultData>
<ns2:PayVaultData>
<ns2:name>expDate</ns2:name>
<ns2:value>012025</ns2:value>
</ns2:PayVaultData>
<ns2:PaymentType>
<ns2:Method>CC</ns2:Method>
<ns2:Detail>Visa</ns2:Detail>
</ns2:PaymentType>
</ns2:Status>
</ns2:LookUpVaultResponse>
</ns2:SingleVaultResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Try this:
$string2 = 'your xml sting';
$doc = new DOMDocument;
$doc->loadXML($string2);
echo "status => ".$doc->getElementsByTagName('Status')->item(0)->nodeValue;
I have XML document captured from a link and anytime I use simplexml_load_file(), it gives me an error saying *Warning: simplexml_load_file(): https://kga-dev.mirakl.net/api/shops?:1: parser error : Start tag expected, '<' not found in C:\wamp\www\merchants\get_merchants.php on line 6*
This is a part of my xml file
<body>
<shops>
<shop>...</shop>
<shop>
<approval_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<approval_rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<order_messages_response_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<banner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<billing_info>
<bank_city xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bank_name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bank_street xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<zip_code xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<iban xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<owner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</billing_info>
And this is my simple php code
<?php
$apiLink = "https://kga-dev.mirakl.net/api/shops?";
$xml=simplexml_load_file($apiLink);
print_r($xml);
//echo $xml->shop_id;
?>
The solution for this problem is, that the API serves a JSON encoded string instead of an XML string. So the delivered content can not be parsed with SimpleXML. Try to get it with the following example
$content = file_get_contents($apiLink);
$data = json_decode($content);
In this case $data should be an object or array with all the data the api delivers.
Are you sure that this is the same XML as returned to the script? Note that you are not calling :1 - I cannot check as it requires authorization, yet in the example given by you there is no error up to line 7 so it would mean that possibly something else is returned as the code below works:
<?php
$s = '<body>
<shops>
<shop>...</shop>
<shop>
<approval_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<approval_rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<order_messages_response_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<banner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</shop>
</shops>
</body>';
$xml=simplexml_load_string($s);
print_r($xml);
?>
Is not the authorization the problem your end? I need to authorize to your webservice: you handle that in a different way for your IP or something like that?
Your Code
<approval_rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
use single quotes
<?php
echo "<order_messages_response_delay xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/>";
?>