Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
371
PHP SimpleXML: Function LoadXML
PHP Version: PHP 5
Description
The function parses the XML
contained in the string source. This function may also be called
statically to load and create a DOMDocument object.
The static invocation may be used when no DOMDocument
properties need to be set prior to loading.
Usage
mixedDOMDocument->loadXML ( string source)
The source is the string representation of XML document.
Example
of How to use loadXML:
<?php
$xmlstr = <<<XML
<employee>
<employeename>test</employeename>
<employeeaddress>test123</employeeaddress>
<SSN>12343456</SSN>
<company>TOPXML</company>
</employee>
XML;
$dom = new domDocument;
$dom->loadXML($xmlstr);
$s_dom = simplexml_import_dom($dom);
echo
"The name of the employee is <B>"
. $s_dom->employeename[0]."</B>";
echo
"<BR>The address of the employee is <B>"
. $s_dom->employeeaddress[0]."</B>" ;
?>
In the above example, I
first created a new XML document from the domDocumentclass by using the new keyword, and then I pull XML string( $xmlstr) into the DOMDocument
object using the loadXMLfunction of the object. Finally, I echo
out the contents of employeename
and employeeaddress.