0
我有一個看起來像這樣的XML文件,我想解析爲常規XML,嘗試循環值,尤其是Cell
值。在PHP中解析XML名稱空間格式
<APIReport xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Rochester.Models">
<Column xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:string>Name</d2p1:string>
<d2p1:string>Surname</d2p1:string>
</Column>
<Dates>29-04-2016, 00:00:00 - 29-04-2016, 23:59:59</Dates>
<Id>1200</Id>
<Row>
<APIReportRow>
<Cell xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string>Francesco</d4p1:string>
<d4p1:string>Delolli</d4p1:string>
</Cell>
</APIReportRow>
<APIReportRow>
<Cell xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string>Roberto</d4p1:string>
<d4p1:string>Delolli</d4p1:string>
</Cell>
</APIReportRow>
</Row>
<Title>Nomi</Title>
所以我試圖解析它在PHP中使用SimpleXML,使用這種簡單的代碼:
$xml = simplexml_load_string($xmlstring);
print_r($xml);
但Cell
值爲空:
SimpleXMLElement Object
(
[Column] => SimpleXMLElement Object
(
)
[Dates] => 29-04-2016, 00:00:00 - 29-04-2016, 23:59:59
[Id] => 1200
[Row] => SimpleXMLElement Object
(
[APIReportRow] => Array
(
[0] => SimpleXMLElement Object
(
[Cell] => SimpleXMLElement Object
(
)
)
[1] => SimpleXMLElement Object
(
[Cell] => SimpleXMLElement Object
(
)
)
)
)
[Title] => Nomi
)
我的問題很簡單:我如何獲得XML的Cell
值?
您是否嘗試過直接訪問到一些小區基站的價值?像這樣:echo(string)$ xml-> Row-> APIReportRow [0] - > Cell; – nanocv
單元格值不爲空,'print_r'不能處理SimpleXML的精彩:P訪問'Cell'內部元素的關鍵是他們使用「namespaces」(標籤中帶有':')。爲此,你需要['children()'方法](http://php.net/manual/en/simplexmlelement.children.php)。 – IMSoP