43
43
44
44
class XML2Array {
45
45
46
- private static $ xml = null ;
47
- private static $ encoding = 'UTF-8 ' ;
48
- private static $ prefix_attributes = '@ ' ;
46
+ protected static $ xml = null ;
47
+ protected static $ encoding = 'UTF-8 ' ;
48
+ protected static $ prefix_attributes = '@ ' ;
49
49
50
50
/**
51
51
* Initialize the root XML node [optional]
@@ -62,13 +62,14 @@ public static function init($version = '1.0', $encoding = 'UTF-8', $format_outpu
62
62
/**
63
63
* Convert an XML to Array
64
64
* @param string $node_name - name of the root node to be converted
65
+ * @param int - Bitwise OR of the libxml option constants see @link http://php.net/manual/zh/libxml.constants.php
65
66
* @param array $arr - aray to be converterd
66
67
* @return DOMDocument
67
68
*/
68
- public static function &createArray ($ input_xml ) {
69
+ public static function &createArray ($ input_xml, $ options = 0 ) {
69
70
$ xml = self ::getXMLRoot ();
70
71
if (is_string ($ input_xml )) {
71
- $ parsed = $ xml ->loadXML ($ input_xml );
72
+ $ parsed = $ xml ->loadXML ($ input_xml, $ options );
72
73
if (!$ parsed ) {
73
74
throw new Exception ('[XML2Array] Error parsing the XML string. ' );
74
75
}
@@ -88,7 +89,7 @@ public static function &createArray($input_xml) {
88
89
* @param mixed $node - XML as a string or as an object of DOMDocument
89
90
* @return mixed
90
91
*/
91
- private static function &convert ($ node ) {
92
+ protected static function &convert ($ node ) {
92
93
$ output = array ();
93
94
94
95
switch ($ node ->nodeType ) {
@@ -155,7 +156,7 @@ private static function &convert($node) {
155
156
/*
156
157
* Get the root XML node, if there isn't one, create it.
157
158
*/
158
- private static function getXMLRoot (){
159
+ protected static function getXMLRoot (){
159
160
if (empty (self ::$ xml )) {
160
161
self ::init ();
161
162
}
0 commit comments