(PHP 5)
simplexml_load_string — Transforma uma string XML em objeto
$data
[, string $class_name
[, int $options
[, string $ns
[, bool $is_prefix
]]]] )Recebe uma string XML bem formada (well-formed) e retorna um objeto.
data
Uma string XML bem formada
class_name
Você pode utilizar o parâmetro opcional simplexml_load_string() para retornar um objeto da classe especificada. the specified class. Esta classe deve extender a classe SimpleXMLElement.
options
A partir do PHP 5.1.0 e da Libxml 2.6.0, você pode também utilizar o parâmetro
options
para especificar parâmetros adicionais da Libxml.
ns
is_prefix
Retorna um objeto da classe SimpleXMLElement com
propriedades contendo os dados do documento XML. Quando houver erro, irá retornar
FALSE
.
Exemplo #1 Interpreta uma string XML
<?php
$string = <<<XML
<?xml version='1.0'?>
<document>
<title>Forty What?</title>
<from>Joe</from>
<to>Jane</to>
<body>
I know that's the answer -- but what's the question?
</body>
</document>
XML;
$xml = simplexml_load_string($string);
var_dump($xml);
?>
O exemplo acima irá imprimir:
SimpleXMLElement Object ( [title] => Forty What? [from] => Joe [to] => Jane [body] => I know that's the answer -- but what's the question? )
Nesse ponto você já pode utilizar $xml->body para acessar as propriedades.