Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:45:28+00:00 2026-05-30T09:45:28+00:00

I do a SOAP-call to my client. It returns a XML-document as a string

  • 0

I do a SOAP-call to my client. It returns a XML-document as a string (this is a workaround that I can’t do anything about). I have the XML in a variable and I need to read this XML to grab the information I want.

I am looking for the fields DomesticCustomer, Addresses and GridOwner. I guess if someone helps me to get to the DomesticCustomer-part I can do the rest on my own.

Note: In this example, there is only one entry under each field, but there could be multiple, so I need to be able to foreach this.

Note #2: Because the client I use has some weird workaround for this to work, the response (the xml) is a simple string.

The XML is:

<?xml version="1.0" encoding="utf-8"?>
<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>
        <MeteringPointIdResponse xmlns="http://www.ediel.no/schemas/public/nubix/MeteringPointIdResponse">
            <RequestId xmlns="">3423424234</RequestId>
            <Requestor xmlns="">
                <GLN>234234234</GLN>
            </Requestor>
            <Customers xmlns="">
                <DomesticCustomer>
                    <LastName>Name</LastName>
                    <FirstName>Name</FirstName>
                    <BirthDate>xxx-xx-xx</BirthDate>
                    <MeterNumber>xxxxx</MeterNumber>
                    <Addresses>
                        <Address>
                            <Address1>345345</Address1>
                            <PostCode>3514</PostCode>
                            <Location>xxxxxx</Location>
                            <CountryCode>xx</CountryCode>
                            <Installation>
                                <Description>xxxxx</Description>
                                <MeteringPointId>xxxxxxxxxxxxxxx</MeteringPointId>
                                <MeteringMethod>xxxxxx</MeteringMethod>
                                <InstallationStatus>xxxx</InstallationStatus>
                                <LastReadOffDate>xxxx-xx-xx</LastReadOffDate>
                            </Installation>
                            <GridOwner>
                                <GLN>xxxxxxx</GLN>
                                <Name>xxxxxxxx</Name>
                                <ProdatAddress>
                                    <InterchangeRecipient>
                                        <Id>xxxxxxx</Id>
                                        <Qualifier>xx</Qualifier>
                                        <Subaddress>xxxxx</Subaddress>
                                    </InterchangeRecipient>
                                    <Party>
                                        <Id>xxxxxxxxxx</Id>
                                        <CodeListResponsible>xxxx</CodeListResponsible>
                                    </Party>
                                    <EDISyntax>
                                        <CharSet>xxx</CharSet>
                                        <SyntaxId>xxxx</SyntaxId>
                                    </EDISyntax>
                                    <SMTPAddress>test@hey.com</SMTPAddress>
                                </ProdatAddress>
                            </GridOwner>
                        </Address>
                    </Addresses>
                </DomesticCustomer>
            </Customers>
        </MeteringPointIdResponse>
    </soap:Body>
</soap:Envelope>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:45:30+00:00Added an answer on May 30, 2026 at 9:45 am

    If you use the built in library for php, it parses the response and returns a mixed object/array object that is INFINITELY easier to deal with than the xml

    Edit: since you are using php’s built in client, here is a simple class that I wrote built around it. It “flattens” the responce and makes it easy to retrieve responces like:

    $soap = new SOAP($wsdl, $options);
    $soap->call("stuff goes here");
    $soap->find("what you are looking for goes here");
    
        /**
         * @author Troy Knapp
         * @copyright 2011
         * 
         * @version .1.1
         */
    
    class Soap {
    
        //***VARIABLES***//
    var $request; //..............string; holds last soap request
    var $requestHeaders; //.......string; holds the headers for the last request
    var $response; //.............string; xml response
    var $responseHeaders; //......string; holds the headers for the last response
    var $result; //...............array; the soap response parsed into an array
    var $wsdlLocation; //.........string; url for the wsdl
    var $parameters; //...........array; saved array of parameters
    var $function; //.............string; name of function to be accessed
    var $findResult = array();
    var $flatArray = array(); //..array; holds an easy to search array
    //
    //***OBJECTS***//
    var $client; //...................instance of SoapClient
    var $exception; //................obj; SoapFault exception object
    //    
    //***DEFAULTS***//
    public $options = array(
        'trace' => 1
    );
    
    function __construct($wsdl, $options = false) {
        if ($options == false) {
            $options = $this->options;
        } else {
            $this->options = $options;
        }
    
        $this->wsdlLocation = $wsdl;
    
        $this->client = new SoapClient($wsdl, $options);
    }
    
    /*
     * Executes a given function when supplied the proper function name, 
     * parameters and options.
     */
    function call($function, $parameters, $options=NULL) {
        $this->function = $function;
        $this->parameters = $parameters;
    
        try {
            //$this->response = $this->client->__soapCall($function, $parameters, $options);
            $this->response = $this->client->$function($parameters, $options);
        } catch (SoapFault $exception) {
            $this->$exception = $exception;
        }
    
        //get info about the last request
        $this->request = $this->client->__getLastRequest();
        $this->requestHeaders = $this->client->__getLastRequestHeaders();
    
        //more info about the last responce
        $this->responseHeaders = $this->client->__getLastResponseHeaders();
    
        //set up an easily searchable array of results
        $this->flatten();
    
        return $this->response;
    }
    
    /*
     * Prints all kinds of interesting info about what went on for debugging 
     * purposes
     */
    function printInfo() {
        echo '<h2>SoapClient Info:</h2>';
        echo 'wsdl location: ' . $this->wsdl_location . '<br/>';
        echo 'SoapClient Options:';
        echoPre($this->options);
    
        echo '<h2>Call Info:</h2>';
        echo 'Function Name: ' . $this->function . '<br/>';
        echo 'Parameters: ';
        echoPre($this->parameters);
    
    
        echo '<h2>Last Request: <br></h2>';
        echo $this->format($this->request);
    
        echo '<h2>Request Headers: <br></h2>';
        echo $this->format($this->requestHeaders);
    
        echo '<h2>Last Response: <br></h2>';
        echoPre($this->response);
    
        echo '<h2>Response Headers: <br></h2>';
        echo $this->format($this->responseHeaders);
    }
    
    /*
     * Formats the xml to make it nice and purdy for display and debugging
     * purposes
     */
    function format($xml) {
    
        // add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)
        $xml = preg_replace('/(>)(<)(\/*)/', "$1\n$2$3", $xml);
    
        // now indent the tags
        $token = strtok($xml, "\n");
        $result = ''; // holds formatted version as it is built
        $pad = 0; // initial indent
        $matches = array(); // returns from preg_matches()
        // scan each line and adjust indent based on opening/closing tags
        while ($token !== false) :
    
            // test for the various tag states
            // 1. open and closing tags on same line - no change
            if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) :
                $indent = 0;
            // 2. closing tag - outdent now
            elseif (preg_match('/^<\/\w/', $token, $matches)) :
                $pad--;
            // 3. opening tag - don't pad this one, only subsequent tags
            elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) :
                $indent = 1;
            // 4. no indentation needed
            else :
                $indent = 0;
            endif;
    
            // pad the line with the required number of leading spaces
            $line = str_pad($token, strlen($token) + $pad, ' ', STR_PAD_LEFT);
            $result .= $line . "\n"; // add to the cumulative result, with linefeed
            $token = strtok("\n"); // get the next token
            $pad += $indent; // update the pad size for subsequent lines    
        endwhile;
    
        $result = highlight_string($result);
    
        //nl2br(htmlentities($result));
        return $result;
    }
    
    /*
     * Searches the pre flattened array for a given key. If there is only one
     * result, this will return a single value, if there are multiple results,
     * it will return an array of values.
     * 
     * @param string; $search - search for a response with this key
     */
    function find($search=false) {
        if ($search == false) {
            return $this->flatArray;
        } else {
            if (isset($this->flatArray[$search])) {
                $result = $this->flatArray[$search];
            } else {
                return false;
            }
        }
    
        if(count($result)==1){
            return $result[0];
        }
        else{
            return $result;
        }
    }
    
    /*
     * This method flattens an array/object result into an array that is easy 
     * to search through. Search terms are set as keys with results set as 
     * arrays owned by said keys.
     */
    
    function flatten($array=false) {
        if ($array == false) {
            $array = $this->response;
        }
        if (is_object($array)) {
            //get the variables of object
            $array = get_object_vars($array);
        }
    
        //howdy('array');
        //echoPre($array);
        //echo "_______________<br>";
    
        if (is_array($array)) {
    
            //loop through the sub elements and make sure they are arrays
            foreach ($array as $key => $value) {
                //if it's an object, we need to convert it to an array
                if (is_object($value)) {
                    //get the variables of object
                    $value = get_object_vars($value);
                }
    
                //echo "key: $key value: ";
                //echoPre($value);
                //echo "_______________<br>";
    
                //push the key=>value pairs to the flat array
                if (!isset($this->flatArray[$key])) {
                    $this->flatArray[$key] = array();
                }
    
                array_push($this->flatArray[$key], $value);
    
                if (is_array($value)) {
                    $this->flatten($value);
                }
            }
        }
    }
    
    function getWSDL() {
        $wsdl = file_get_contents($this->wsdlLocation);
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a call to a SOAP WCF Service that returns a lot of
I have a SOAP client in Ruby that I'm trying to get working with
Its quite simpel: How do i call a web-service which can receive a XML-String
I have make a soap-call with Savon. This works fine and give the following
I'm running into this problem when trying to call a SOAP Web Service from
We have SOAP web services in production that are relying on SOAP Headers (containing
I have an incoming soap message wich form is TStream (Delphi7), server that send
I am learning about SOAP implementation and have become somewhat confused regarding the appropriate
I have a SOAP request that is known to work using a tool like,
I have php web service. and can consume it from php client. But problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.