How can i parse below xml by php? - php

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns0:GetListBy_QualificationResponse xmlns:ns0="urn:WS_CTM_People_ICEVA">
<ns0:getListValues>
<ns0:Person_ID>PPL000000301739</ns0:Person_ID>
<ns0:Submitter>soehler</ns0:Submitter>
<ns0:Profile_Status>Enabled</ns0:Profile_Status>
<ns0:Locale2>en_US</ns0:Locale2>
<ns0:VIP>No</ns0:VIP>
<ns0:Client_Sensitivity>Standard</ns0:Client_Sensitivity>
</ns0:getListValues>
</ns0:GetListBy_QualificationResponse>
</soapenv:Body>
</soapenv:Envelope>

Use Simple HTML Dom class. for example:
include('simple_html_dom.php');
$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns0:GetListBy_QualificationResponse xmlns:ns0="urn:WS_CTM_People_ICEVA">
<ns0:getListValues>
<ns0:Person_ID>PPL000000301739</ns0:Person_ID>
<ns0:Submitter>soehler</ns0:Submitter>
<ns0:Profile_Status>Enabled</ns0:Profile_Status>
<ns0:Locale2>en_US</ns0:Locale2>
<ns0:VIP>No</ns0:VIP>
<ns0:Client_Sensitivity>Standard</ns0:Client_Sensitivity>
</ns0:getListValues>
</ns0:GetListBy_QualificationResponse>
</soapenv:Body>
</soapenv:Envelope>';
$xml = str_get_html($xml);
print_r( $xml );
Read class documents and extract data from $xml variable.

Related

Fetching Data Using SOAPUI work but Unable to get data using PHP . Why?

I am Trying to get the same data which I got using SOAPUI in PHP as I can't export in PHP.
See My WSDL file. The function I am calling is AUXTableAdminstration.
If I am fetching the whole table the PHP code works but if I use anything between <web:xDoc> </web:xDoc> then I am having trouble.
Input SOAP Request in SOAPUI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webcominc.com/">
<soapenv:Header/>
<soapenv:Body>
<web:AUXTableAdministration>
<!--Optional:-->
<web:userName>UserName</web:userName>
<!--Optional:-->
<web:password>Password</web:password>
<!--Optional:-->
<web:action>EXPORTROWS</web:action>
<!--Optional:-->
<web:tableName>ContactData</web:tableName>
<web:xDoc>
<Root>
<Columns>
<Column>ContactInternalId</Column>
<Column>ContactName</Column>
</Columns>
<SearchCriteria>
<Value>12345</Value>
<Value>TestName</Value>
</SearchCriteria >
</Root>
</web:xDoc>
</web:AUXTableAdministration>
</soapenv:Body>
</soapenv:Envelope>
I am searching the row values using the above Request
OUTPUT for SOAPUI
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AUXTableAdministrationResponse xmlns="http://webcominc.com/">
<AUXTableAdministrationResult>
<Result>
<Status>OK</Status>
<Message>action 'EXPORT' for ContactData succeeded</Message>
<Root>
<Columns>
<Column>CpqTableEntryId</Column>
<Column>ContactInternalId</Column>
<Column>ContactName</Column>
<Column>CustomerInternalId</Column>
<Column>Company</Column>
</Columns>
<Rows>
<Row>
<Value>1234</Value>
<Value>1234</Value>
<Value>Test Value</Value>
<Value>86392</Value>
<Value>Erin Test2</Value>
</Row>
</Rows>
</Root>
</Result>
</AUXTableAdministrationResult>
</AUXTableAdministrationResponse>
</soap:Body>
</soap:Envelope>
PHP file I am using with WSDL:
<?php
header('Content-Type: application/xml; charset=utf-8');
ini_set('soap.wsdl_cache_enable', '0');
$username ="username";
$password = "password";
$action = "EXPORTROWS";
$tablename= "ContactData";
$xml ="<Root><Columns><Column>ContactInternalId</Column><Column>ContactName</Column></Columns><SearchCriteria><Value>86393</Value><Value>Erin Hensz</Value></SearchCriteria></Root>";
$parameters= array('userName' => $username,'password' => $password,'action' => $action,'tableName' => $tablename,xDoc => $xml);
$options = array('soap_version'=>SOAP_1_1,'exceptions'=>true,'trace'=>1,'cache_wsdl'=>WSDL_CACHE_NONE);
$client = new SoapClient('https://sandbox.webcomcpq.com/wsAPI/wssrv.asmx?WSDL' , $options);
$data = $client->AUXTableAdministration($parameters);
echo $result= $client->__getLastResponse();
?>
PHP OUTPUT
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AUXTableAdministrationResponse xmlns="http://webcominc.com/">
<AUXTableAdministrationResult>
<Result xmlns="http://webcominc.com/">
<Status>NOK</Status>
<Message>EXPORTROWS failed</Message>
<Error>
<ErrorCode>100000</ErrorCode>
<Description>
Object reference not set to an instance of an object.
</Description>
</Error>
</Result>
</AUXTableAdministrationResult>
</AUXTableAdministrationResponse>
</soap:Body>
</soap:Envelope>

SOAP envelope with header authentication call php

I have to consume a webservice, but can't find a proper way to create the call.
This is the xml the company provide as example
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Qpay.POS.Gateway.ServiceContracts" xmlns:urn1="urn:Qpay.POS.Gateway.DataContracts">
<soapenv:Header/>
<soapenv:Body>
<urn:GetProvidersRequest>
<!--Optional:-->
<urn:Header>
<urn1:CertPublicKey>XX-XX-XX-XX-XX</urn1:CertPublicKey>
<!--Optional:-->
<urn1:UIID>XX</urn1:UIID>
<urn1:User>XXXX</urn1:User>
</urn:Header>
</urn:GetProvidersRequest>
</soapenv:Body>
</soapenv:Envelope>
Tried using this:
$soapURL = "https://pos.qpay123.biz/dBar/Gateway.svc?" ;
$soapParameters = Array('UIID' => "63", 'User' => "System") ;
$soapFunction = "GetProvidersRequest" ;
$soapClient = new SoapClient($soapURL, $soapParameters);
$soapResult = $soapClient->__soapCall($soapFunction) ;
var_dump($soapResult);
But i get a false as var dump, can you point me on the right direction to solve it?
Thanks

how to parsing SOAP Response in PHP?

I just started with web service using SOAP.
I using below code to get response.
$response = $objClient->__getLastResponse();
My response is:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getHotelValuedAvail xsi:type="xsd:string" xmlns:ns1="http://axis.frontend.hydra.hotelbeds.com">
<HotelValuedAvailRS xmlns="http://www.hotelbeds.com/schemas/2005/06/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" timeToExpiration="1771163" totalItems="387" echoToken="DummyEchoToken">
<PaginationData currentPage="1" totalPages="387"/>
<ServiceHotel xsi:type="ServiceHotel" availToken="ngQXOz+UOoLDtPieFMhu9wdw">
<DateFrom date="20130709"/>
<DateTo date="20130711"/>
<Currency code="EUR">Euro</Currency>
<HotelInfo xsi:type="ProductHotel">
<Code>99361</Code>
<Name>Hilton Sa Torre Mallorca Resort</Name>
<Position latitude="39.42761529999999936535" longitude="2.75602390000000019299"/>
</HotelInfo>
</ServiceHotel>
</HotelValuedAvailRS>
</ns1:getHotelValuedAvail>
</soapenv:Body>
</soapenv:Envelope>
Can some one help me to get the value of Name Element?
I have tried simplexml_load_string($response) and and X-Path("/Name"), but i could not get it.
You can try using DOMDocument::getElementsByTagName :
You can try like this:
$response = $objClient->__getLastResponse();
$doc = new DOMDocument();
$doc->loadXML($response);
$names= $doc->getElementsByTagName( "Name" );
$name = $names->item(0)->nodeValue;
var_export( $name );

Processing Soap response with PHP

I've tried several examples on here so far but just can't seem to figure out how to process this soap response with PHP 5.3:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getAuthenticationTokenResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://earthquake">
<getAuthenticationTokenReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1CFA9FF89E1F6E2AC62C4E5A689EED65F144B7E827C386A60836D97A76E0C49F47FCC94637AFADB8EAEDF3110955F2622AB334B92EBFC568E563662C2202E51157A4D9AABBFDD9941119CC8C96681B51EE453006C460B50C6104A5E07C84CE88</getAuthenticationTokenReturn>
</ns1:getAuthenticationTokenResponse>
</soapenv:Body>
</soapenv:Envelope>
I'm trying to get the getAuthenticationTokenReturn into a varaible but have not had much luck so far.
Here is my code so far:
$xml = simplexml_load_string($result);
$xml->registerXPathNamespace('ns1','http://schemas.xmlsoap.org/soap/encoding/');
foreach ($xml->xpath('//ns1:getAuthenticationTokenResponse') as $item)
{
echo 'Name: '.$item,'<br>';
}
Try this, i have tried and i got the token
$string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getAuthenticationTokenResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://earthquake">
<getAuthenticationTokenReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1CFA9FF89E1F6E2AC62C4E5A689EED65F144B7E827C386A60836D97A76E0C49F47FCC94637AFADB8EAEDF3110955F2622AB334B92EBFC568E563662C2202E51157A4D9AABBFDD9941119CC8C96681B51EE453006C460B50C6104A5E07C84CE88</getAuthenticationTokenReturn>
</ns1:getAuthenticationTokenResponse>
</soapenv:Body>
</soapenv:Envelope>';
$xml = simplexml_load_string($string);
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('ns1', 'http://earthquake');
foreach ($xml->xpath('//ns1:getAuthenticationTokenResponse') as $item)
{
echo $item->asXML();
}

WSDL Client Problem With PHP

I would like to send the following XML request to a WSDL web service :
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-'.$nonce.'">
<wsse:Username>xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxx</wsse:Password>
</wsse:UsernameToken>
<wsu:Timestamp wsu:Id="Timestamp-'.$nonce.'" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>'.$timestamp.'</wsu:Created>
<wsu:Expires>'.$expiration.'</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<prep:requestListeSeancesCtrlAcces>
<codeManifestation>xxxx</codeManifestation>
<!--Optional:-->
<debutIntervalle/>
<!--Optional:-->
<finIntervalle/>
</prep:requestListeSeancesCtrlAcces>
</soapenv:Body>
</soap:Envelope>
How can I do this? I tried PHP soap extension and also NuSOAP with no success :(
Thanks for your help.
Have you tried HttpRequest::send ? E.g. see the example at http://www.php.net/manual/en/function.httprequest-send.php#95734 and fill in your own data:
<?php
//set up variables
$theData = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-'.$nonce.'">
<wsse:Username>xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxxx</wsse:Password>
</wsse:UsernameToken>
<wsu:Timestamp wsu:Id="Timestamp-'.$nonce.'" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>'.$timestamp.'</wsu:Created>
<wsu:Expires>'.$expiration.'</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<prep:requestListeSeancesCtrlAcces>
<codeManifestation>xxxx</codeManifestation>
<!--Optional:-->
<debutIntervalle/>
<!--Optional:-->
<finIntervalle/>
</prep:requestListeSeancesCtrlAcces>
</soapenv:Body>
</soap:Envelope>';
$url = 'http://www.example.com';
$options = array();
//create the httprequest object
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST, $options);
//add the content type
$httpRequest_OBJ->setContentType = 'Content-Type: text/xml';
//add the raw post data
$httpRequest_OBJ->setRawPostData ($theData);
//send the http request
$result = $httpRequest_OBJ->send();
//print out the result
echo "<pre>"; print_r($result); echo "</pre>";
?>
when i consume wsdl i use cURL
for modifying headers and Envelopes use this:
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapenvelope);

Categories