我有一个位于指定URL的xml文件,其中包含一个沉淀概率节点,该节点有几个"value“元素,它们的schema-instance声明允许它们为nillable。但是,php中的attributes()函数不显示此元素的XSI声明。
$feedURL= "http://forecast.weather.gov/MapClick.php?lat=32.78520&lon=-79.99400&FcstType=dwml";
// read feed into SimpleXML object
$wxml = simplexml_load_file($feedURL);
echo $wxml->data->parameters->{'probability-of-precipitation'}->value[0]->attributes();可以打印'XSI属性‘吗??谢谢
发布于 2011-11-05 07:21:57
对于这个$feedURL变量,传递的XML文件包含一个XML namespace指令,该指令指定"XSI“前缀的名称空间由URI "http://www.w3.org/2001/XMLSchema-instance.”引用。
因此,为了访问与value元素对应的attributes (@ attributes )集合,您需要在attributes函数参数值中指定此URI,例如:
print_r($wxml->data->parameters->{'probability-of-precipitation'}->value[0]->attributes('the_XSI_prefix's_URI'));以上内容将在您的浏览器中输出:
Nil,如果在http://forecast.weather.gov/MapClick.php?lat=32.78520&lon=-79.99400&FcstType=dwml XML文件的当前版本中传递了xsi:nil="true“指令。
https://stackoverflow.com/questions/8004134
复制相似问题