-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSimpleXmlReader.php
More file actions
51 lines (42 loc) · 1.52 KB
/
SimpleXmlReader.php
File metadata and controls
51 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace SimpleXmlReader;
class SimpleXmlReader
{
const RETURN_DOM = 'RETURN_DOM';
const RETURN_SIMPLE_XML = 'RETURN_SIMPLE_XML';
const RETURN_INNER_XML_STRING = 'RETURN_INNER_XML_STRING';
const RETURN_OUTER_XML_STRING = 'RETURN_OUTER_XML_STRING';
protected $xmlReader;
protected function __construct()
{
$this->xmlReader = new ExceptionThrowingXMLReader();
}
public static function autoOpenXML($path, $encoding = 'UTF-8', $options = 0)
{
if (strtolower(substr($path, -3)) == '.gz') {
return self::openGzippedXML($path, $encoding, $options);
} else {
return self::openXML($path, $encoding, $options);
}
}
public static function openXML($path, $encoding = 'UTF-8', $options = 0)
{
$simpleXmlReader = new self();
$simpleXmlReader->xmlReader->open($path, $encoding, $options);
return $simpleXmlReader;
}
public static function openGzippedXML($path, $encoding = 'UTF-8', $options = 0)
{
return self::openXML("compress.zlib://$path", $encoding, $options);
}
public static function openFromString($source, $encoding = 'UTF-8', $options = 0)
{
$simpleXmlReader = new self();
$simpleXmlReader->xmlReader->XML($source, $encoding, $options);
return $simpleXmlReader;
}
public function path($path, $returnType = self::RETURN_SIMPLE_XML, $callback = null)
{
return new PathIterator($this->xmlReader, $path, $returnType, $callback);
}
}