4343
4444class XML2Array {
4545
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 = '@ ' ;
4949
5050 /**
5151 * Initialize the root XML node [optional]
@@ -62,13 +62,14 @@ public static function init($version = '1.0', $encoding = 'UTF-8', $format_outpu
6262 /**
6363 * Convert an XML to Array
6464 * @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
6566 * @param array $arr - aray to be converterd
6667 * @return DOMDocument
6768 */
68- public static function &createArray ($ input_xml ) {
69+ public static function &createArray ($ input_xml, $ options = 0 ) {
6970 $ xml = self ::getXMLRoot ();
7071 if (is_string ($ input_xml )) {
71- $ parsed = $ xml ->loadXML ($ input_xml );
72+ $ parsed = $ xml ->loadXML ($ input_xml, $ options );
7273 if (!$ parsed ) {
7374 throw new Exception ('[XML2Array] Error parsing the XML string. ' );
7475 }
@@ -88,7 +89,7 @@ public static function &createArray($input_xml) {
8889 * @param mixed $node - XML as a string or as an object of DOMDocument
8990 * @return mixed
9091 */
91- private static function &convert ($ node ) {
92+ protected static function &convert ($ node ) {
9293 $ output = array ();
9394
9495 switch ($ node ->nodeType ) {
@@ -155,7 +156,7 @@ private static function &convert($node) {
155156 /*
156157 * Get the root XML node, if there isn't one, create it.
157158 */
158- private static function getXMLRoot (){
159+ protected static function getXMLRoot (){
159160 if (empty (self ::$ xml )) {
160161 self ::init ();
161162 }
0 commit comments