Beispiel #1
0
    /**
     * Convert an XML to Array
     * @param string $node_name - name of the root node to be converted
     * @param array $arr - aray to be converterd
     * @return DOMDocument
     */
    public static function &createArray($input_xml) {
        $xml = self::getXMLRoot();
		if(is_string($input_xml)) {
			$parsed = $xml->loadXML($input_xml);
			if(!$parsed) {
				throw new Exception('[XML2Array] Error parsing the XML string.');
			}
		} else {
			if(get_class($input_xml) != 'DOMDocument') {
				throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
			}
			$xml = self::$xml = $input_xml;
		}
		$array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
        self::$xml = null;    // clear the xml node in the class for 2nd time use.
        return $array;
    }
Beispiel #2
0
 /**
  * Convert an XML to Array
  * @param $input_xml
  * @return DOMDocument
  * @throws Exception
  * @internal param string $node_name - name of the root node to be converted
  * @internal param array $arr - aray to be converterd
  */
 public static function &createArray($input_xml)
 {
     // clean xml comments
     $input_xml = preg_replace('/<!--[\\s\\S\\W\\D]*?-->/', '', $input_xml);
     $input_xml = str_replace(['&', '<br/>', '<br />'], ['&amp;', ' ', ' '], $input_xml);
     $xml = self::getXMLRoot();
     if (is_string($input_xml)) {
         $parsed = $xml->loadXML($input_xml);
         if (!$parsed) {
             throw new Exception('[XML2Array] Error parsing the XML string.');
         }
     } else {
         if (get_class($input_xml) != 'DOMDocument') {
             throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
         }
         $xml = self::$xml = $input_xml;
     }
     $array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
     self::$xml = null;
     // clear the xml node in the class for 2nd time use.
     return $array;
 }
Beispiel #3
0
 /**
  * Convert an XML to Array
  * @param string $node_name - name of the root node to be converted
  * @param array $arr - aray to be converterd
  * @return DOMDocument
  */
 public static function &createArray($input_xml)
 {
     $xml = self::getXMLRoot();
     if (is_string($input_xml)) {
         $parsed = $xml->loadXML($input_xml);
         if (!$parsed) {
             echo "XML String = {$input_xml}\n";
             throw new Exception('[XML2Array] Error parsing the XML string.');
         }
     } else {
         if (get_class($input_xml) != 'DOMDocument') {
             $fhe = fopen("exception.log", "w+");
             # throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.');
             $errmsg = "throw new Exception('[XML2Array] The input XML object should be of type: DOMDocument.')\n";
             fwrite($fhe, $errmsg);
             fclose($fhe);
         }
         $xml = self::$xml = $input_xml;
     }
     $array[$xml->documentElement->tagName] = self::convert($xml->documentElement);
     self::$xml = null;
     // clear the xml node in the class for 2nd time use.
     return $array;
 }