Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中读取XML字符串_Php_Arrays_Xml - Fatal编程技术网

在PHP中读取XML字符串

在PHP中读取XML字符串,php,arrays,xml,Php,Arrays,Xml,在应用simplexml\u load\u字符串时,我很难读取这个XML字符串 XML如下所示:- <?xml version="1.0" encoding="utf-8"?> <Pport xmlns:fc="http://www.thalesgroup.com/rtti/PushPort/Forecasts/v2" xmlns:ct="http://www.thalesgroup.com/rtti/PushPort/CommonType

在应用
simplexml\u load\u字符串时,我很难读取这个XML字符串

XML如下所示:-

<?xml version="1.0" encoding="utf-8"?>                  
 <Pport xmlns:fc="http://www.thalesgroup.com/rtti/PushPort/Forecasts/v2" xmlns:ct="http://www.thalesgroup.com/rtti/PushPort/CommonTypes/v1" ts="2015-04-02T21:40:43.6505299+01:00" version="12.0" xmlns="http://www.thalesgroup.com/rtti/PushPort/v12">
    <uR updateOrigin="TD">          
        <TS rid="201504021071622" uid="L24370" ssd="2015-04-02">        
            <fc:Location tpl="SHRDHST" wta="21:39:30" wtd="21:40" pta="21:40" ptd="21:40">  
                <fc:arr at="21:39" src="TD" />
                <fc:dep at="21:40" src="TD" />
                <fc:plat>2</fc:plat>
            </fc:Location>  
        </TS>       
    </uR>           
 </Pport>

我正在尝试读取
中的内容,您可以通过正确遍历并使用
attributes()
方法获得这些属性

$newxml = simplexml_load_string($xml);
$children = $newxml->uR->TS->children('fc', true)->children('fc', true);

foreach($children as $movedata) {
    $attr = $movedata[0]->attributes();
    $uid = $attr['at'];
    echo $uid . '<br />';
}
$newxml=simplexml\u load\u字符串($xml);
$children=$newxml->uR->TS->children('fc',true)->children('fc',true);
foreach($movedata作为子项){
$attr=$movedata[0]->attributes();
$uid=$attr['at'];
回显$uid。“
”; }

请注意,可以使用
children()
方法访问名称空间。

我认为这与
fc
名称空间有关。请看,您将
var\u dump
的输出与实际数据和XML结构混淆了。与数据库连接的
var_dump
不会转储它所表示的数据库的所有数据一样,它与字符串或文件中simplexmlement的var_转储类似:它不显示整个数据,只显示底层结构的选择。实际上甚至没有数组,输出只是象征性的和简化的。感谢Adeneo的工作。使用此方法如何获取平台号。上面案例中的ie 2提示:这是最后一个子项,
2
是nodeValueAm我是否在正确的轨道上使用$children=$xml->uR->TS->children('fc',true)->children('fc',true)->nodeValue;请尝试
$children->plat[0]->\uuu-toString()
很抱歉在这方面有点慢,但是当我遇到语法错误时,与上面的代码相比,该代码将位于何处$children=$xml->uR->TS->children('fc',true)->children('fc',true);$attr=$children->plat[0]\u toString();echo$attr.“
';
$newxml = simplexml_load_string($xml);
$children = $newxml->uR->TS->children('fc', true)->children('fc', true);

foreach($children as $movedata) {
    $attr = $movedata[0]->attributes();
    $uid = $attr['at'];
    echo $uid . '<br />';
}
$newxml = simplexml_load_string($xml);
$children = $newxml->uR->TS->children('fc', true)->children('fc', true);

foreach($children as $movedata) {
    $attr = $movedata[0]->attributes();
    $uid = $attr['at'];
    echo $uid . '<br />';
}