The simple XML parser
It is used to parse Name, attributes and textual content.
simplexml_load_file()
This function is the one which always requires a file path as mandatory parameter.
simplexml_load_file(($fileName,$class,$options,$ns,$is_prefix)
simplexml_load_string()
This function always required the string.
simplexml_load_string($XMLData,$class,$options,$ns,$is_prefix)
simplexml_import_dom()
This function accepts DOM formatted XML content and it converts into simple XML.
simplexml_load_string($DOMNode,$class)
The following example to parse a xml data file.
<?php
$data = "<?xml version = '1.0' encoding = 'UTF-8'?>
<note>
<Course>Android</Course>
<Subject>Android</Subject>
<Company>TutorialsPoint</Company>
<Price>$10</Price>
</note>";
$xml = simplexml_load_string($data) or die("Error: Cannot create object");
?>
<html>
<head>
<body>
<?php
print_r($xml);
?>
</body>
</head>
</html>
0 Comment(s)