调用未定义的方法 SimpleXMLElement::child_nodes()

发布于 2024-11-03 04:22:44 字数 274 浏览 5 评论 0原文

我有一个代码可以解析从 google 搜索获得的 xml 文本 它以前工作正常,我想更新我的版本信息后它工作不正常

可能是什么问题我收到以下错误

Fatal error: Call to undefined method SimpleXMLElement::child_nodes() in /home/search.php in line 70

请让我知道如何解决这个问题

此代码用于 smarty 它从curl 获取响应字符串。

i am having a code which parses the xml text which is obtained from google search
it used to working fine before , I think after updating my version infos it not working fine

what might be the problem i am getting the following error

Fatal error: Call to undefined method SimpleXMLElement::child_nodes() in /home/search.php in line 70

Please let me know how can i solve this problem

This code is used in smarty
And it gets the response string from curl.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦太阳 2024-11-10 04:22:45

使用以下符号来迭代您的 xml(更改“myfile.xml”和“tagName”):

<?php
include('simple_html_dom.php');
if (file_exists('myfile.xml')) {
    $xml = simplexml_load_file('myfile.xml');
    print_r($xml);
    foreach( $xml->children() AS $child ) {
        $name = $child->getName();
        if ($name == 'tagName') {
            foreach( $child->children() AS $grandchild ) {
                // DO SOMETHING
            }
        }
    }
}
?>

还有其他更优雅的方法来实现此目的,但这是一个简单的初学者方法。有关技术信息: https://www.php.net/manual/en/类.simplexmlelement.php

use the following notation to iterate thru your xml (change 'myfile.xml' and 'tagName'):

<?php
include('simple_html_dom.php');
if (file_exists('myfile.xml')) {
    $xml = simplexml_load_file('myfile.xml');
    print_r($xml);
    foreach( $xml->children() AS $child ) {
        $name = $child->getName();
        if ($name == 'tagName') {
            foreach( $child->children() AS $grandchild ) {
                // DO SOMETHING
            }
        }
    }
}
?>

there are other more elegant ways to achieve this, but this is a simple beginner's way to do it. for technical info: https://www.php.net/manual/en/class.simplexmlelement.php

耳根太软 2024-11-10 04:22:44

SimpleXMLElement 没有名为 child_nodes。您是否在寻找 children 方法?

SimpleXMLElement does not have a method called child_nodes. Were you looking for the children method?

古镇旧梦 2024-11-10 04:22:44

好的,非常感谢您的回答。

我通过使用 domxml-php4-to-php5.php 文件解决了我的问题,我刚刚上传了该文件并将该文件名包含在我的文件中。结果成功了。

我从这个链接得到了该文件: http://alexandre.alapetite.fr/ doc-alex/domxml-php4-php5/

:)

okay many thanx for your answers .

i got solved my problem by using the domxml-php4-to-php5.php file i have just uploaded this file and included that file name in my file . And it got worked .

I got that file from this link : http://alexandre.alapetite.fr/doc-alex/domxml-php4-php5/

:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文