繁体   English   中英

SimpleXMLElement对象缺少节点

[英]SimpleXMLElement Object is missing nodes

我正在使用simplexml_load_string解析XML数据。 一切正常,除了1个例外,其中某些子节点似乎丢失了。 这是原始XML输出的示例:

<LEAGUE Name="NFL Football">
    <EVENT GameID="371667" Title="Kansas City Chiefs at Oakland Raiders" Date="2014-11-20" Time="20:25" Timezone="EST" Status="SCHEDULED" Enabled="true">
        <TOTALS Over="42.5" OverOdds="-110.0" OverEnabled="true" Under="42.5" UnderOdds="-110.0" UnderEnabled="true"/>
        <CONTESTANT Name="Kansas City" Score="0" RotationNumber="109">
            <LINE Money="-355.0" MoneyEnabled="true" Points="-7.5" Odds="-115.0" PointsEnabled="true"/>
        </CONTESTANT>
        <CONTESTANT Name="Oakland" Score="0" RotationNumber="110">
            <LINE Money="295.0" MoneyEnabled="true" Points="7.5" Odds="-105.0" PointsEnabled="true"/>
        </CONTESTANT>
    </EVENT>

除LINE节点外,其他所有内容均正常加载。 如果我执行print_r,则显示如下(为简洁起见,跳至“竞赛”节点):

[CONTESTANT] => Array
    (
        [0] => SimpleXMLElement Object
            (
                [@attributes] => Array
                    (
                        [Name] => Kansas City
                        [Score] => 0
                        [RotationNumber] => 109
                    )

                [0] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [Money] => -355.0
                                [MoneyEnabled] => true
                                [Points] => -7.5
                                [Odds] => -115.0
                                [PointsEnabled] => true
                            )

                    )

            )

子节点中的数据在那里(Money,MoneyEnabled等),但是不在预期的LINE节点中。 实际上,我一直无法通过SimpleXML对象访问此信息。 使用CakePHP的调试功能,甚至不会显示LINE数据。 我在所有地方都使用了此功能,这是唯一一次不显示任何SimpleXML数据的地方。 使用CakePHP的调试:

object(SimpleXMLElement) {
@attributes => array(
    'GameID' => '371667',
    'Title' => 'Kansas City Chiefs at Oakland Raiders',
    'Date' => '2014-11-20',
    'Time' => '20:25',
    'Timezone' => 'EST',
    'Status' => 'SCHEDULED',
    'Enabled' => 'true'
)
TOTALS => object(SimpleXMLElement) {
    @attributes => array(
        'Over' => '42.5',
        'OverOdds' => '-110.0',
        'OverEnabled' => 'true',
        'Under' => '42.5',
        'UnderOdds' => '-110.0',
        'UnderEnabled' => 'true'
    )
}
CONTESTANT => array(
    (int) 0 => object(SimpleXMLElement) {
        @attributes => array(
            'Name' => 'Kansas City',
            'Score' => '0',
            'RotationNumber' => '109'
        )
    },
    (int) 1 => object(SimpleXMLElement) {
        @attributes => array(
            'Name' => 'Oakland',
            'Score' => '0',
            'RotationNumber' => '110'
        )
    }
)

如您所见,每个CONTESTANT节点下都没有LINE节点。

不了解CAKE,但不信任print_r ,因此不信任带有SimpleXML var_dump()

宁可

$xml = simplexml_load_string($x); // assume XML in $x
echo $xml->asXML();

而且,XML已完成,请参见操作: https : //eval.in/224134

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM