从SimpleXMLElement对象中的包含连字符的字段获取值

时间:2016-11-15 23:11:09

标签: php

我正在加载一个来自商业软件的xml文件。如果我print_r($xml)我得到这样的东西:

SimpleXMLElement Object (
 [records] => SimpleXMLElement Object (
     [record] => SimpleXMLElement Object (
         [database] => SomeData
         [ref-type] => SomeData
         [contributors] => SimpleXMLElement Object (
             [authors] => SimpleXMLElement Object (
                 [author] => Array (
                     [0] => SomeData
                     [1] => SomeData
                     [2] => SomeData
                     [3] => SomeData
                     [4] => SomeData
                )
            )
        )
    )
)

我用这个

提取所需的数据
$MyNewArray['DataBase'] = (string) $xml->records->record->database;

但是当有连字符时(有几个带连字符的字段)无法获取数据:

$MyNewArray['ReferenceType'] = (string) $xml->records->record->ref-type;

有人知道解决方案吗?

0 个答案:

没有答案