2013-04-26 65 views
0

我有這個xml內容。我需要從fullName屬性中獲取值。我已經嘗試過使用lib.xml解析器。但它不起作用。你能幫我實現嗎?提前致謝。使用PHP的XML解析器

<?xml version="1.0" encoding="UTF-8"?><currentUserDetails firstName="3rdParty" fullName="3rdParty Access" lastName="Access" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" xmlns=""/> 

回答

4

使用simplexml

$xml = simplexml_load_string($x); // assuming XML in $x 
echo $xml['fullName']; 

看到它的工作:http://codepad.viper-7.com/7KVHcU

+0

當我的$ XML [ '全名']分配給會話變量 \t $ _SESSION [「fullusername 「] = $ xml ['fullName']; 它顯示爲 \t [fullusername] => SimpleXMLElement對象 ( [0] =>的3rdParty訪問 ) – user2118463 2013-04-26 11:07:14

+0

@ user2118463:投給字符串:'$測試=(字符串)$ XML [ '全名'];' – michi 2013-04-26 16:23:18

0
$xmlFile = "http://www.domaine.com/city.xml"; 

$data  = simplexml_load_file($xmlFile); 

print_r($data);