PHP.nl

simplexml_load_string

simplexml_load_string

Interprets a string of XML into an object

 **simplexml_load_string** string $data  $class_name int $options string $namespace_or_prefix bool $is_prefix

Takes a well-formed XML string and returns it as an object.

dataA well-formed XML string

class_name You may use this optional parameter so that will return an object of the specified class. That class should extend the class. simplexml_load_string``SimpleXMLElement

options``namespace_or_prefixNamespace prefix or URI.

is_prefix true if is a prefix, false if it's a URI; defaults to false. namespace_or_prefix

Returns an of class with properties containing the data held within the xml document,return.falseforfailure. object``SimpleXMLElement

Produces an error message for each error found in the XML data. E_WARNING

Tip: > Use to suppress all XML errors, and to iterate over them afterwards. libxml_use_internal_errors``libxml_get_errors

Voorbeeld: Interpret an XML string

<?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);

print_r($xml);
?>
SimpleXMLElement Object
(
  [title] => Forty What?
  [from] => Joe
  [to] => Jane
  [body] =>
   I know that's the answer -- but what's the question?
)
 At this point, you can go about using 
 and such.
`$xml-&gt;body`

simplexml_load_file``SimpleXMLElement::__construct``libxml_use_internal_errors