Php 在元素的属性上保留前缀

Php 在元素的属性上保留前缀,php,xml,xpath,Php,Xml,Xpath,我有以下代码来获取RichText元素的属性。这些属性要么具有类似于s7:的前缀,要么根本没有前缀 <?php $url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&fmt=fxgraw"; $xml = simplexml_load_file($url); $xml->registerXPathNamespace('default', 'http://ns.a

我有以下代码来获取
RichText
元素的属性。这些属性要么具有类似于
s7:
的前缀,要么根本没有前缀

<?php
$url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&fmt=fxgraw";    
$xml = simplexml_load_file($url);       
$xml->registerXPathNamespace('default', 'http://ns.adobe.com/fxg/2008');
$xml->registerXPathNamespace('s7', 'http://ns.adobe.com/S7FXG/2008');
$textNode = $xml->xpath("//default:RichText[@s7:elementID]");

function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }

$result1 = array();
$result2 = array();
foreach($textNode as $node){
    $result1[] = $node->attributes('http://ns.adobe.com/S7FXG/2008');
    $result2[] = $node->attributes();

}

$text = array_merge($result1,$result2);

pr($text);

?>
$result1[]
中收集的所有属性都应该具有
s7:
前缀。但是当它存储xml中的数据时,它从这些属性中剥离了
s7:
。可以看到这一点,因为键0和1的数组值已删除前缀。我需要前缀留在那里,所以它看起来像这样:

//some sample XML - get the attributes
$xml = "<root name='root'><node id='1'>hello</node></root>";
$doc = new SimpleXMLElement($xml);
$attrs = $doc->xpath('//@*');

//iterate over array and add in namespace prefixes      
foreach($attrs as $key => $val) {
    $attrs['s7:'.$key] = $val;
    unset($attrs[$key]);
}

如何防止前缀被剥离,或者在构建阵列时如何将其添加回前缀中

不知道为什么PHP在提取中省略了名称空间-也许对libxml更了解的人可以帮助做到这一点-但是提取后重命名名称就足够简单了

//一些示例XML-获取属性
$xml=“你好”;
$doc=新的simplexmlement($xml);
$attrs=$doc->xpath('/@*');
//迭代数组和外接程序命名空间前缀
foreach($attrs as$key=>$val){
$attrs['s7:'.$key]=$val;
未设置($attrs[$key]);
}
[s7:caps] => none
[s7:colorName] => 
[s7:colorValue] => #518269
[s7:colorspace] => rgb
[s7:elementID] => smalltext

etc...
//some sample XML - get the attributes
$xml = "<root name='root'><node id='1'>hello</node></root>";
$doc = new SimpleXMLElement($xml);
$attrs = $doc->xpath('//@*');

//iterate over array and add in namespace prefixes      
foreach($attrs as $key => $val) {
    $attrs['s7:'.$key] = $val;
    unset($attrs[$key]);
}