本文整理汇总了PHP中XML2Array::xml方法的典型用法代码示例。如果您正苦于以下问题:PHP XML2Array::xml方法的具体用法?PHP XML2Array::xml怎么用?PHP XML2Array::xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML2Array
的用法示例。
在下文中一共展示了XML2Array::xml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Exception
/**
* 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;
}
示例2: Exception
/**
* 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 />'], ['&', ' ', ' '], $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;
}
示例3: Exception
/**
* 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;
}