带有 php simplexml 的 Atom 命名空间

发布于 2024-09-19 05:34:00 字数 719 浏览 2 评论 0原文

这是我加载到 simplexml 对象中的 RSS 模板。我想更改

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <atom:link href="link" rel="self" type="application/rss+xml" />
        <title></title>
        <link></link>
        <description></description>
        <lastBuildDate></lastBuildDate>
    </channel>
</rss>

我想更改atom:link中的href属性,但我不知道如何访问它。我搜索了SO并找到了一堆有关如何访问不同名称空间的信息,但我不知道如何将它们中的任何一个应用到这个特定的示例(主要是因为我非常密集:)

我可以使用以下命令修改我的链接属性下面的代码行但是我如何修改上面提到的属性?

$rss->channel->link = $rssLink;

任何帮助将不胜感激!

This is my RSS template that I load into my simplexml object. I want to change the

<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <atom:link href="link" rel="self" type="application/rss+xml" />
        <title></title>
        <link></link>
        <description></description>
        <lastBuildDate></lastBuildDate>
    </channel>
</rss>

I'd like to change the href attribute in atom:link but I have no clue how to access it. I scoured through SO and found a bunch of information on how to access different namespaces but I can't figure out how to apply any of them to this specific example (mostly because I am pretty dense :)

I can modify my link attribute with the line of code below but how would I modify the attribute mentioned above?

$rss->channel->link = $rssLink;

Any help would be appreciated!

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

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

发布评论

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

评论(1

绳情 2024-09-26 05:35:12
$attrs = $rss->channel->children("atom", true)->link->attributes();
$attrs["href"] = "href_value";

示例此处

$attrs = $rss->channel->children("atom", true)->link->attributes();
$attrs["href"] = "href_value";

Example here.

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