1

I am trying to read the value of location in the following xml:

<service name="xyz">
     <documentation>gSOAP 2.7.11 generated service definition</documentation>
     <port name="xyz" binding="tns:xyz">
      <SOAP:address location="http://192.168.0.222:8092"/>
     </port>
</service>

I am trying to reach SOAP:address tag but unable to:

$wsdlFile = file_get_contents('./wyz.wsdl');

    if($wsdlFile) {
        $xml = simplexml_load_string($wsdlFile);
        foreach( $xml->service->documentation->port->attributes() as $a => $b) {
            echo $a . '-' . $b;
        }
    }

How could I get the value of location?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
  • Possible duplicate of [Parse XML with Namespace using SimpleXML](http://stackoverflow.com/questions/595946/parse-xml-with-namespace-using-simplexml) – michi Dec 01 '15 at 12:18

2 Answers2

0
//Convert to Array like this
$wsdlFile = file_get_contents('./wyz.wsdl');
if($wsdlFile) {
    $wsdlData = json_decode(json_encode($wsdlFile),TRUE);
}
//Now you can access the address through the key=> value pair
$location = $wsdlData['location'];
Gabrielo
  • 50
  • 5
0

Having a : in a property makes it harder to get that property, but is possible:

By index:

$value = $xml->port->children()[0]->attributes()['location']->__toString();

Or by name:

$prop = 'SOAP:address';
$value = $xml->port->$prop->attributes()['location']->__toString();

Print all attributes of SOAP:address and its values:

$wsdlFile = file_get_contents('./wyz.wsdl');

if($wsdlFile) {
    $xml = simplexml_load_string($wsdlFile);
    $prop = 'SOAP:address';
    foreach($xml->port->$prop->attributes() as $a => $b) {
        echo $a . '-' . $b;
    }
}
regapictures
  • 371
  • 3
  • 12