In fact, you need to try different options. Something turns out, something is discarded.
For example, you can use simplexml_load_string
- Interprets a string with XML into an object [ Documentation ]
And then you can get to the desired item through the parents, using ->
for objects
For example:
$client = new SoapClient("http://nbrb.by/Services/ExRates.asmx?WSDL", array("trace" => 1, "exceptions" => 0 )); $result = $client->CurrenciesRefDaily()->CurrenciesRefDailyResult->any; $xml = simplexml_load_string($result); echo 'Result xml: '. $result; echo '<pre>'; print_r($xml->NewDataSet->DailyCurrenciesRef->Cur_QuotName); echo '</pre>';
the latest print_r
will print 1 албанский лек
or using domDocument
- Represents all the contents of an HTML or XML document; serves as the root of the document tree. Documentation
And specifically its loadXML
method - Loading XML from a string. Next you can work with getElementsByTagName
and other methods, for example:
$xml = <<< XML <?xml version="1.0" encoding="utf-8"?> <books> <book>Patterns of Enterprise Application Architecture</book> <book>Design Patterns: Elements of Reusable Software Design</book> <book>Clean Code</book> </books> XML; $dom = new DOMDocument; $dom->loadXML($xml); $books = $dom->getElementsByTagName('book'); foreach ($books as $book) { echo $book->nodeValue, PHP_EOL; }