1

私はxmlファイルを持っています:

<?xml version="1.0" ?>
<xml>
<opis lang="en">My text</opis>
<opis lang="cz">My text2</opis>
</xml>

「My text2」を取得したいので、属性 lang が「cz」であるノード:

$xml = simplexml_load_file($fileName);
$result = $xml->xpath('//xml/opis[@lang="cz"]')

しかし、価値の代わりに私は得る:

array(1) (
  [0] => SimpleXMLElement object {
    @attributes => array(1) (
      [lang] => (string) cz
    )
  }
))
4

2 に答える 2

0

DomDocument を使用してみてください:

$xml = new DomDocument;
$xml->load('yourFile');
$xpath = new DomXpath($xml);

foreach ($xpath->query('//xml/opis[@lang="cz"]') as $rowNode) {
  echo $rowNode->nodeValue; // will be 'this item'
}
于 2013-04-01T11:26:17.093 に答える