<?php
header('Content-type: text/plain');
include('lib.xml.php');
$xml = new Xml;
// PARSE
// Parse from a source into a variable (default source type : FILE)
$source = '<?xml version="1.0" encoding="utf-8"?>
<test>
<this a="b">
<is c="d">
<a e="f" g="h"> first test</a>
</is>
<is>
<b hello="world">second test</b>
</is>
</this>
</test>';
$out = $xml->parse($source, NULL);
print_r($out);
/* will output
Array
(
[this] => Array
(
[is] => Array
(
[0] => Array
(
[a] => first test
[a-ATTR] => Array
(
[e] => f
[g] => h
)
)
[1] => Array
(
[b] => second test
[b-ATTR] => Array
(
[hello] => world
)
)
)
[is-ATTR] => Array
(
[c] => d
)
)
[this-ATTR] => Array
(
[a] => b
)
)
*/
// Parse from a local file
$out = $xml->parse('myfile.xml', 'FILE');
print_r($out);
// Parse from a Web file
$out = $xml->parse('http://site.tld/myfile.xml', 'CURL');
print_r($out);
// ENCODING
// You could specify an encoding type (default : utf-8)
$out = $xml->parse('myfile.xml', 'FILE', 'ISO-8859-15');
print_r($out);
// have fun ;-)
?>
|