Results 1 to 2 of 2

Thread: unable to parse soap xml in php

  1. #1
    Join Date
    Apr 2016
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default unable to parse soap xml in php

    I am trying to get shipping cost from DHL using soap . I got result as xml string

    Code:
    string(376) "<?xml version="1.0" encoding="utf-8"?><Details><ShippingCharge>2002.190</ShippingCharge><TotalTaxAmount>305.420</TotalTaxAmount></Details>"
    simplexml_load_string function not parsing response. Is there anyway to get data from xml element

    Thank you

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    2,429
    Thanks
    5
    Thanked 290 Times in 283 Posts

    Default

    Hi there captainbarner,

    I would suggest tha you use simplexml_load_file rather than simplexml_load_string

    Using a sample xml file from https://www.learningcontainer.com/sample-xml-file/,
    here is a basic example...

    PHP Code:
    <?php
     $xmldata 
    simplexml_load_file(
      
    "https://www.learningcontainer.com/wp-content/uploads/2020/03/Sample-employee-XML-file.xml"
       or die(
    "Failed to load");
    ?>
    <!DOCTYPE HTML>
    <html lang="en">
    <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

    <title>using xml data</title>

    <link rel="stylesheet" href="screen.css" media="screen">

    <style media="screen">
    body {
        background-color: #f9f9f9;
        font: normal 1em / 1.5em  sans-serif;
     }
    h1{
        font-size: 1.5em;
        color: #444;
        text-align: center;
     }
    table {
        margin: auto;
        border-collapse: collapse;
        background-color: #fff;
    }
    th,td {
        padding: 0.25em 0.5em;
        border: 1px solid #000;
    }
    </style>

    </head>
    <body>

    <h1>PHP display XML content</h1>

    <table>
    <thead>
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Title</th>
    <th>Division</th>  
    <th>Building</th>
    <th>Room</th>
    </tr>
    </thead>
    <tbody>
    <?php 
    foreach($xmldata->children() as $empl) { 
    echo 
    "<tr>\n";        
     echo 
    "<td>"$empl->firstname "</td>\n";     
     echo 
    "<td>"$empl->lastname "</td>\n";     
     echo 
    "<td>"$empl->title "</td>\n";        
     echo 
    "<td>"$empl->division "</td>\n";
     echo 
    "<td>"$empl->building "</td>\n";
     echo 
    "<td>"$empl->room "</td></tr>\n"

    ?>
    </tbody>
    </table>

    </body>
    </html>
    Note

    You will need to upload this code as a PHP file to your site for it to work or use a local server such as XAMPP

    coothead
    Last edited by coothead; 05-27-2022 at 05:31 PM. Reason: additiional information
    ~ the original bald headed old fart ~

Similar Threads

  1. Replies: 0
    Last Post: 04-13-2010, 08:50 PM
  2. Soap Box :cool:
    By Dal in forum The lounge
    Replies: 10
    Last Post: 07-27-2008, 06:50 PM
  3. PayPal Soap interface?
    By ReMaX in forum PHP
    Replies: 0
    Last Post: 05-06-2008, 05:12 PM
  4. parse error
    By kosi in forum PHP
    Replies: 4
    Last Post: 08-24-2007, 08:07 AM
  5. Ajax and soap
    By kosi in forum JavaScript
    Replies: 1
    Last Post: 06-08-2007, 03:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •