不能从withdb .xml中使用SimpleXML获取值


can't get a value with SimpleXML from wiitdb.xml

我请求帮助,因为我做了一切,但我不能得到概要值。我的代码是:

<?php
$xml=simplexml_load_file("wiitdb.xml") or die("Error: Cannot create object");
$b = 'D2SE18';
$a = $xml->xpath("//game/id[.='" . $b ."']/parent::*");
$result = $a[0];
echo "name: " . $result['name'] . "<br>";
echo "ID: " . $result->id . "<br>";
echo "type: " . $result->type . "<br>";
echo "region: " . $result->region . "<br>";
echo "languages: " . $result->languages . "<br>";
echo "title EN: " . $result->locale[0]->title . "<br>";
echo "synopsis EN: " . $result ->locale[0]->children('synopsis', TRUE) . "<br>";
print_r($a);
?>

它的作用是查找一个ID,然后显示该元素的父元素的值。

当我运行它时,它显示:

name: Deca Sports 2 (Demo) (USA) (EN,FR,ES)
ID: D2SE18
type: 
region: NTSC-U
languages: EN,FR,ES
title EN: Deca Sports 2 (Demo)
synopsis EN: 
Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => Deca Sports 2 (Demo) (USA) (EN,FR,ES) ) [id] => D2SE18 [type] => SimpleXMLElement Object ( ) [region] => NTSC-U [languages] => EN,FR,ES [locale] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [lang] => EN ) [title] => Deca Sports 2 (Demo) [synopsis] => SimpleXMLElement Object ( ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [lang] => ES ) [title] => Deca Sports 2 (Demo) [synopsis] => Prueba tus destrezas deportivas a través de una gran variedad de actividades en Deca Sports 2. Afina tus habilidades en cada deporte en y crea tu propio equipo personalizado con el nuevo editor. Exhibe tus destrezas en una variedad de opciones de un solo jugador o compite con amigos y familiares en los modos multijugador. ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [lang] => ZHTW ) [title] => 運動大集錦2 試玩版(美) [synopsis] => SimpleXMLElement Object ( ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [lang] => ZHCN ) [title] => 德卡运动会2 试玩版(美) [synopsis] => SimpleXMLElement Object ( ) ) ) [developer] => HUDSON SOFT CO., LTD. [publisher] => Hudson Entertainment, Inc. [date] => SimpleXMLElement Object ( [@attributes] => Array ( [year] => 2009 [month] => 1 [day] => 1 ) ) [genre] => sports [rating] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => ESRB [value] => E ) ) [wi-fi] => SimpleXMLElement Object ( [@attributes] => Array ( [players] => 0 ) ) [input] => SimpleXMLElement Object ( [@attributes] => Array ( [players] => 4 ) [control] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => wiimote [required] => true ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => nunchuk [required] => true ) ) ) ) [rom] => SimpleXMLElement Object ( [@attributes] => Array ( [version] => [name] => Deca Sports 2 (Demo) (USA) (EN,FR,ES).iso [size] => 4699979776 ) ) ) )

即使我尝试用

echo "synopsis EN: " . $result->locale[0]->synopsis . "<br>";

它没有显示值"synopsis"

我怎样才能得到它?

xml文件的一个例子是:

<game name="Deca Sports 2 (Demo) (USA) (EN,FR,ES)">
        <id>D2SE18</id>
        <type/>
        <region>NTSC-U</region>
        <languages>EN,FR,ES</languages>
        <locale lang="EN">
            <title>Deca Sports 2 (Demo)</title>
            <synopsis>It's a top-ten all over again as Deca Sports 2 offers another all-you-can-play buffet of ten games anyone can enjoy. The all-around collection has something for everyone, with tennis, darts, ice hockey, motorcycle racing, synchronized swimming, speed skating, downhill skiing, bocce, kendo, and dodgeball. Multiple single and multiplayer modes offer tournaments, head-to-head matches, skill contests, and league play. Use the Team Editor to customize everything about your squad, including your team's name, logo, and colors, plus the looks and skills of the players themselves. And, just to make sure the playing field is level, beginners can learn the ropes of any of the sports in Tutorial Mode. (The Demo lets you play 4 sports of the 10!)</synopsis>
        </locale>
        <locale lang="ES">
            <title>Deca Sports 2 (Demo)</title>
            <synopsis/>
        </locale>
        <locale lang="ZHTW">
            <title>運動大集錦2 試玩版(美)</title>
            <synopsis/>
        </locale>
        <locale lang="ZHCN">
            <title>德卡运动会2 试玩版(美)</title>
            <synopsis/>
        </locale>
        <developer>HUDSON SOFT CO., LTD.</developer>
        <publisher>Hudson Entertainment, Inc.</publisher>
        <date year="2009" month="1" day="1"/>
        <genre>sports</genre>
        <rating type="ESRB" value="E"/>
        <wi-fi players="0"/>
        <input players="4">
            <control type="wiimote" required="true"/>
            <control type="nunchuk" required="true"/>
        </input>
        <rom version="" name="Deca Sports 2 (Demo) (USA) (EN,FR,ES).iso" size="4699979776"/>
    </game>

在locale:

中命名空间前缀的概要中没有子节点
$result->locale[0]->children('synopsis', TRUE)

因此你没有得到任何输出,它有0个子元素:

var_dump($a[0]->children('synopsis', TRUE)->count()); # int(0)

你可能更想找

$result->locale[0]->synopsis;

即默认命名空间中名为<synopsis>的元素