Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

php - SimpleXML get node value

Say I have this following XML structure:

<?xml version="1.0" encoding="UTF-8"?>
<main>
    <parent>
        <child1>some value</child1>
        <child2>another value</child2>
    </parent>
</main>

I made a variable of the XML and now I want to get the values of child1, so I use SimpleXML:

$xml = new SimpleXMLElement($xml);
$this->xmlcode = (string) $xml->main->parent->child1;

But I get this message: Notice: Trying to get property of non-object in /x.php on line x

I also tried it with $xml->parent->child1, but no success.

Anyone??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$xml = new SimpleXMLElement($xml);
$this->xmlcode = (string) $xml->parent[0]->child1;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...