simplexml_load_string
(PHP 5)
simplexml_load_string --
Interpreta una cadena XML en un objeto
Descripción
object
simplexml_load_string ( string data [, string class_name [, int options]] )
Esta función tomará una cadena xml válida
data y devolverá un object de clase
SimpleXMLElement con propiedades conteniendo la información del
documento xml. Si ocurre cualquier error, se devolverá FALSE.
También puedes usar el parámetro opcional class_name de forma
que simplexml_load_string() devolverá un objeto de la clase
especificada. Esa clase debe extender la clase
SimpleXMLElement.
Desde PHP 5.1.0 y Libxml 2.6.0, también puedes usar el parámetro
options para especificar parámetros de Libxml adicionales.
Ejemplo 1. Interpreta una cadena 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); ?>
|
This script will display:
SimpleXMLElement Object
(
[title] => Forty What?
[from] => Joe
[to] => Jane
[body] =>
I know that's the answer -- but what's the question?
) |
A partir de aquí, puedes puedes acceder al nodo body mediante $xml->body
y a cualquier otro elemento.
|
Vea también: simplexml_load_file().