I am trying to use the str_replace()
function to remove the S:Envelope
and S:Body
tags from my Soap XML output. Despite many attempts I have been unable to remove these tags. I need to remove the tags so that I can pull data from the XML output using logic such as echo $xml->vinDescription->WorldManufacturerIdentifier . "<br>";
With the Soap tags present, I am unable to do this.
Here is my XML output (note.xml):
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<VehicleDescription xmlns="urn:description7b.services.chrome.com" country="US" language="en" modelYear="2008" bestMakeName="Audi" bestModelName="S4" bestStyleName="5dr Avant Wgn">
<responseStatus responseCode="Successful" description="Successful"/>
<vinDescription vin="WAUUL78E38A092113" modelYear="2008" division="Audi" modelName="S4" styleName="5dr Avant Wgn" bodyType="Wagon 4 Dr." drivingWheels="AWD" builddata="no">
<WorldManufacturerIdentifier>Germany Audi Nsu</WorldManufacturerIdentifier>
<restraintTypes>
<group id="9">Safety</group>
<header id="38">Air Bag - Frontal</header>
<category id="1001">Driver Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="38">Air Bag - Frontal</header>
<category id="1002">Passenger Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="39">Air Bag - Side</header>
<category id="1005">Front Side Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="39">Air Bag - Side</header>
<category id="1007">Front Head Air Bag</category>
</restraintTypes>
<restraintTypes>
<group id="9">Safety</group>
<header id="39">Air Bag - Side</header>
<category id="1008">Rear Head Air Bag</category>
</restraintTypes>
<marketClass id="53">Small Wagon</marketClass>
</vinDescription>
</VehicleDescription>
</S:Body>
And my PHP code with the str_replace()
:
<html>
<body>
<?php
$response = "note.xml";
$clean_xml = str_replace(['<S:Body>','<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">'],'', $response);
$xml=simplexml_load_file($clean_xml) or die("Error: Cannot create object");
echo $xml->vinDescription->WorldManufacturerIdentifier . "<br>";
?>
</body>
</html>