У меня есть XML-файлSimpleXMLElement объект разборе
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<comments
xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<authors>
<author></author>
</authors>
<commentList>
<comment authorId="0" ref="G2">
<text>
<t xml:space="preserve"> test comment 1</t>
</text>
</comment>
<comment authorId="0" ref="G4">
<text>
<t xml:space="preserve"> test comment 2</t>
</text>
</comment>
</commentList>
</comments>
я загрузить его с помощью SimpleXMLElement функции PHP
$com = new SimpleXMLElement('data.xml');
когда я print_r ($ ком) я получаю
SimpleXMLElement Object
(
[authors] => SimpleXMLElement Object
(
[0] => SimpleXMLElement Object
()
)
[commentList] => SimpleXMLElement Object
(
[comment] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[authorId] => 0
[ref] => G2
)
[text] => SimpleXMLElement Object
([t] => test comment 1)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[authorId] => 0
[ref] => G4
)
[text] => SimpleXMLElement Object
(
[t] => test comment 2
)
)
)
)
)
я хочу читать комментарии, используя значения ref, я попытался прочитать значение G2, как
echo $value = (string) $comments->commentList->comment[0]->ref['G2'];
, но не успех, любая идея, как считывать значения с помощью значений реф как G2, G4
Вы пытаетесь получить значение 'ref' атрибута или вы пытаетесь найти комментарии, где' ref' атрибута соответствует определенное значение? –
ya хочу найти комментарий, где значение значения соответствует G2 G4, тогда необходимо прочитать комментарий – user889030