Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Odczytanie danych z XML
maruder99
post 28.02.2012, 12:15:31
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 27.01.2012

Ostrzeżenie: (0%)
-----


Witam wszystkich.

Przyznaje, ze jestem raczej zielony w zagadnieniach XML. Moj problem polega na tym, ze chce wyciagnac konkretna wartosc z pliku XML i nie do konca jestem zadowolony z rezultatu.


To jest wzorzec odwolania do webservice:
CODE

POST /tracking.asmx HTTP/1.1
Host: adreswebservice.domena.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.domena.com/GetAffiliateGroupRevenueByUniqueId"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetAffiliateGroupRevenueByUniqueId xmlns="http://domena.com/">
<strUniqueId>string</strUniqueId>
</GetAffiliateGroupRevenueByUniqueId>
</soap:Body>
</soap:Envelope>



To jest odpowiedz webservice:

CODE


HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetAffiliateGroupRevenueByUniqueIdResponse xmlns="http://domena.com">
<GetAffiliateGroupRevenueByUniqueIdResult>
<intReturnCode>int</intReturnCode>
<strReturnMessage>string</strReturnMessage>
<intLeadId>int</intLeadId>
<strExpressConsent>string</strExpressConsent>
<strFindBrokerRequestGUID>string</strFindBrokerRequestGUID>
<dblLeadCost>double</dblLeadCost>
</GetAffiliateGroupRevenueByUniqueIdResult>
</GetAffiliateGroupRevenueByUniqueIdResponse>
</soap:Body>
</soap:Envelope>



A to kod, ktorym dysponuje na chwile obecna. Chcialbym jednak wyciagnac tylko wartosc leada smile.gif

  1. function callWS() {
  2.  
  3. $host = "adreswebservice.domena.com";
  4. $port = 80;
  5. $uri = "http://adreswebservice.domenacom/tracking.asmx";
  6. $affid = $_GET['affid'];
  7.  
  8. //Host and port must be set here!
  9. $fp = fsockopen($host, $port, $errno, $errstr, 30);
  10.  
  11. if (!$fp) {
  12. $a["errorstring"] = $errstr;
  13. $a["errno"] = $errno;
  14. return $a;
  15. } else {
  16. // creating the response message with headers
  17. $out = "POST $uri HTTP/1.1\r\n";
  18. $out .= "Host: ".$_SERVER['SERVER_NAME']."\r\n";
  19. $out .= "Connection: Close\r\n";
  20.  
  21. //Content must be assembled here because of the Content-Length HTTP header.
  22.  
  23. $content = '<?xml version="1.0" encoding="utf-8"?>
  24. <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  25. <soap:Body>
  26. <GetAffiliateGroupRevenueByUniqueId xmlns="http://domena.com/">
  27. <strUniqueId>'.$affid.'</strUniqueId>
  28. </GetAffiliateGroupRevenueByUniqueId>
  29. </soap:Body>
  30. </soap:Envelope>';
  31.  
  32. $out .= "Content-Type: text/xml; charset=utf-8\r\n";
  33. $out .= "Content-Length: ". strlen($content)."\r\n\r\n";
  34. $out .= $content;
  35.  
  36. fwrite($fp, $out);
  37. //Retrieving response message
  38. $response = "";
  39. while (!feof($fp)) {
  40. $response .= fgets($fp, 128);
  41. }
  42. fclose($fp);
  43.  
  44.  
  45. //echo "**".$response."**";
  46.  
  47. //checking if we've got back intReturnCode. If not, we will handle the response as an error response.
  48. if (strpos($response,"<intReturnCode>") != FALSE) {
  49. $intReturnCode = substr($response,strpos($response,"<intReturnCode>")+100, strpos($response,"</intReturnCode>")-2-strpos($response,"<intReturnCode>")-14 );
  50. $strReturnMessage = substr($response,strpos($response,"<strReturnMessage>")+249, strpos($response,"</strReturnMessage>")-20-strpos($response,"<strReturnMessage>")-24);
  51. $a["intReturnCode"] = $intReturnCode;
  52. $a["strReturnMessage"] = $strReturnMessage;
  53.  
  54.  
  55. } else {
  56. $a["errno"] = 777;
  57. $a["errorstring"] = "No intReturnCode provided in the response XML data.";
  58. $a["strReturnMessage"] = substr($response,strpos($response,"<strReturnMessage>")+18, strpos($response,"</strReturnMessage>")-1-strpos($response,"<strReturnMessage>")-17);
  59. }
  60. //print $response;
  61. return $a;
  62. }
  63.  
  64. }
  65.  
  66. //Example function call
  67. $e = callWS();
  68.  
  69. //Example data processing with basic error checking.
  70. if (!isset($e["errno"])) {
  71. echo $e["intReturnCode"];
  72. echo "Your earnings are: <b>";
  73. echo $e["strReturnMessage"];
  74. echo "</b>";
  75. } else {
  76. echo $e["errno"]." - ". $e["errorstring"];
  77. }
  78.  
  79.  
  80.  
  81. ?>



Oczywiscie za pomoca normalnego formularza przekazuje zmienna $affid. Bylbym wdzieczny za jakies sugestie. Dzieki.


Naprawde nikt nie jest w stanie dac jakiejs odpowiedzi?
Go to the top of the page
+Quote Post
thek
post 28.02.2012, 14:41:11
Post #2





Grupa: Moderatorzy
Postów: 4 362
Pomógł: 714
Dołączył: 12.02.2009
Skąd: Jak się położę tak leżę :D




A od czego są biblioteko DOMDocument lub SimpleXML? smile.gif


--------------------
Najpierw był manual... Jeśli tam nie zawarto słów mądrości to zapytaj wszechwiedzącego Google zadając mu własciwe pytania. A jeśli i on milczy to Twój problem nie istnieje :D
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.04.2024 - 09:44