0
XMLファイルがあり、普通のXMLとして解析したい、とりわけCell
の値をループするtryngをしたい。 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>
は、だから私は、この単純なコードを使用して、SimpleXMLを持つPHPでそれを解析してみました:
$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
の値を取得するにはどうすればよいですか? @IMSoPへ
あなたは、いくつかのセルのノードの値に直接アクセスしようとしたことがありますか?何かが好きです:echo(string)$ xml-> Row-> APIReportRow [0] - > Cell; – nanocv
セルの値は空ではなく、 'print_r'はSimpleXMLのawesomenessに対処できません:P' Cell'の要素にアクセスするための鍵は、 "namespaces"(それらに ':'を含むタグ)を使用することです。そのためには、[children() 'メソッド](http://php.net/manual/en/simplexmlelement.children.php)が必要です。 – IMSoP