Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要关于删除xml行的建议吗_C#_Xpath - Fatal编程技术网

C# 需要关于删除xml行的建议吗

C# 需要关于删除xml行的建议吗,c#,xpath,C#,Xpath,我正在使用CMS,发现了一个从文件夹中的内容生成rss提要的功能。但是,我希望从列表中删除其中一行。我已经做了研究,我“认为”我应该使用XmlDocument类来帮助我删除我不想要的行。我使用了Firebug和FirePath来获取XPath,但我似乎不知道如何恰当地应用它。我还不确定是应该使用.Load还是.LoadXml——我使用了后一种seing,好像提要显示得很好。但是,我必须转换为ToString()以消除重载的匹配错误 我要删除的行称为“存档平面” 我为FirePath获得的XPat

我正在使用CMS,发现了一个从文件夹中的内容生成rss提要的功能。但是,我希望从列表中删除其中一行。我已经做了研究,我“认为”我应该使用XmlDocument类来帮助我删除我不想要的行。我使用了Firebug和FirePath来获取XPath,但我似乎不知道如何恰当地应用它。我还不确定是应该使用.Load还是.LoadXml——我使用了后一种seing,好像提要显示得很好。但是,我必须转换为ToString()以消除重载的匹配错误

我要删除的行称为“存档平面” 我为FirePath获得的XPath是“/*[@id='feedContent']/xhtml:div[11]/xhtml:h3/xhtml:a”

我还假设.RemoveChild(node);将在I Response.Write之前将其从rssData中删除。谢谢

Object rssData = new object();
Cms.UI.CommonUI.ApplicationAPI AppAPI = new Cms.UI.CommonUI.ApplicationAPI();
rssData = AppAPI.ecmRssSummary(50, true, "DateCreated", 0, "");
Response.ContentType = "text/xml";

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.LoadXml(rssData.ToString());

XmlNode node = xmlDocument.SelectSingleNode(@"xhtml:div/xhtml:h3/xhtml[a = 'Archived Planes']");

    if (node != null)
    {
        node.ParentNode.RemoveChild(node);
    }

Response.Write(rssData);
编辑以包含以下输出
这是rssData的response.write输出的内容:
平面进给
http://www.domain.rss1.aspx
新飞机
http://www.domainx1.aspx
这是描述
安得烈
2012年8月16日星期四格林威治标准时间15:55:53
存档平面
http://www.domain23.aspx
存档平面的说明
简
2012年8月15日星期三10:34:23 GMT


我怀疑您的xpath不正确,它看起来像是引用的某个时髦的dom元素,而不是xml元素。。。e、 g.对于以下xml

<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<NewDataSet>
 <userinfo>
     <username>pqr2</username>
     <pass>abc</pass>
     <addr>abc</addr>
 </userinfo>

 <userinfo>
     <username>pqr1</username>
     <pass>pqr2</pass>
     <addr>pqr3</addr>
 </userinfo>
</NewDataSet>

我想我会发布答案,尽管我会标记Pauls作为答案,因为他的代码/建议是我进一步研究的基础。我仍然不知道SelectSingleNode中的“@”是什么,也不知道我是否真的应该使用它——我会做更多的研究

    Object rssData = new object();
    Cms.UI.CommonUI.ApplicationAPI AppAPI = new Cms.UI.CommonUI.ApplicationAPI();
    rssData = AppAPI.ecmRssSummary(50, true, "DateCreated", 0, "");
    Response.ContentType = "text/xml";
    Response.ContentEncoding = System.Text.Encoding.UTF8;

    XmlDocument xmlDocument = new XmlDocument();

    xmlDocument.LoadXml(rssData.ToString());

    XmlNode node = xmlDocument.SelectSingleNode("rss/channel/item[title = 'Archived Planes']");

    if (node != null)
        try
        {
            node.ParentNode.RemoveChild(node);
            xmlDocument.Save(Response.Output);
        }
        catch { }

    else { Response.Write(rssData); }
}

@符号只是表示一个逐字的字符串文字(与普通字符串声明相比,允许在字符串中使用时髦的字符),例如


请参见

谢谢,我想我已经找到了XPath,这似乎可以在xmlDocument中使用@符号的用途是什么?我把它去掉了,它似乎起作用了。最后一个难题是如何保存到rssData对象,因为.save我认为只保存到物理文件?谢谢-这很有意义。将再次添加@登录
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"file.xml");
XmlNode node = xmlDocument.SelectSingleNode(@"NewDataSet/userinfo[username = 'pqr1']");

if (node != null) {
  node.ParentNode.RemoveChild(node);
  xmlDocument.Save(@"file.xml");
}
    Object rssData = new object();
    Cms.UI.CommonUI.ApplicationAPI AppAPI = new Cms.UI.CommonUI.ApplicationAPI();
    rssData = AppAPI.ecmRssSummary(50, true, "DateCreated", 0, "");
    Response.ContentType = "text/xml";
    Response.ContentEncoding = System.Text.Encoding.UTF8;

    XmlDocument xmlDocument = new XmlDocument();

    xmlDocument.LoadXml(rssData.ToString());

    XmlNode node = xmlDocument.SelectSingleNode("rss/channel/item[title = 'Archived Planes']");

    if (node != null)
        try
        {
            node.ParentNode.RemoveChild(node);
            xmlDocument.Save(Response.Output);
        }
        catch { }

    else { Response.Write(rssData); }
}
string e = "Joe said \"Hello\" to me";      // Joe said "Hello" to me
string f = @"Joe said ""Hello"" to me";   // Joe said "Hello" to me