2011-11-04 95 views
1

我具有位於所指定的URL,它包括概率的沉澱的節點,其具有其架構實例聲明(多個)允許它們的nillable幾個「值」元素的XML文件。但是,php中的attributes()函數並不顯示此元素的XSI聲明。使用PHP,如何訪問由XML模式聲明聲明的XML元素的屬性?

$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屬性'? 謝謝

回答

0

對於此$ feedURL變量,傳遞的XML文件包含一個XML名稱空間指令,該指令指定URI「http://www.w3」引用「XSI」前綴的名稱空間。組織/ 2001/XMLSchema的實例「。

所以,爲了訪問對應於該值的屬性(@屬性)集合[0]元件,則需要的屬性功能參數值的範圍內指定此URI,例如:

print_r($wxml->data->parameters->{'probability-of-precipitation'}->value[0]->attributes('the_XSI_prefix's_URI')); 

上面將輸出在瀏覽器中:

Nil, 

如果XSI:無=「true」指令在http://forecast.weather.gov/MapClick.php?lat=32.78520&lon=-79.99400&FcstType=dwml XML文件的最新版本通過。

+0

對XML命名空間和前綴的W3C詳解於:http://www.w3schools.com/XML/xml_namespaces.asp – user377241