DOM从RSS XML中移除子项 [英] DOM Remove Child from RSS XML

查看:159
本文介绍了DOM从RSS XML中移除子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望我可以得到一些帮助,PHP不是我的强项,还在学习绳索...

Hoping I can get some help with this, PHP is not my strong point, still learning the ropes...

所以我有一个PHP表单,创建一个RSS文件,RSS提要将由帮助台工作人员在内部内部网上使用,以及时了解网络中出现的当前问题。

So I have a php form that creates an RSS file, the RSS feed will be used on an internal intranet by helpdesk staff to keep up to date with current issues that arise in the network.

该表单旨在用作管理饲料的前端,最后我需要做的是能够从饲料中删除特定的物品。

The form is intended to be used as a front end for managing the feed and the last thing I need to do is be able to delete a specific item from the feed.

我想删除物品的使用特定的GUID,当表单创建项目时,GUID只是使用time()给出一个值,我被困在我甚至找到我想要删除的项目,我想我需要搜索项目以匹配guid元素然后删除它出现的孩子...有人可以给我一些有用的指针吗?

I want to delete item's with specific GUID's, when the form creates the item the GUID is simply given a value using time(), I'm stuck at how I even find the item I want to delete, I guess I need to search the items to match the guid element then delete the child it appears in... can someone give me some helpful pointers?

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <item>
      <title>Exchange Server being rebooted</title>
      <description>Exchange servers are currently being rebooted</description>
      <author>Self</author>
      <link></link>
      <pubDate>Fri, 26 Aug 2011 08:37:12</pubDate>
      <guid>1314311832</guid>
    </item>
  </channel>
</rss>

当我以RSS的格式显示项目时,我将与GUID建立链接

When I display the items from the RSS in the form I'll be putting a link with the GUID that when clicked should delete that item.

希望这是有道理的。

谢谢,

推荐答案

您可以使用DOMXPath检索GUID元素和removeChild()来删除它们:

You may use DOMXPath to retrieve the GUID-elements and removeChild() to remove them:

$xpath    = new DOMXPath($yourDOMDocument);
$query = '//rss/channel/item/guid[boolean(.="1314311832")]';
$entries  = $xpath->query($query);

foreach ($entries as $entry) {
    $entry->parentNode->parentNode->removeChild($entry->parentNode);
}

这篇关于DOM从RSS XML中移除子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆