使用 C# .NET 4 去除 xml 属性 id

发布于 2024-11-11 18:32:27 字数 78 浏览 2 评论 0原文

我正在将一些 xml 传递到服务器,在执行 POST 时,我需要删除属性 id,但我不知道如何使用 c# 来做到这一点,

谢谢

I'm passing some xml to a server and when doing a POST I need to strip the attribute id's, but I'm not sure how to do that using c#

Thanks

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

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

发布评论

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

评论(2

人│生佛魔见 2024-11-18 18:32:27
var myDoc = XDocument.Load("C:\\mydoc.xml")
myDoc.Descendants("myNode").Attributes("id").Remove();
var myDoc = XDocument.Load("C:\\mydoc.xml")
myDoc.Descendants("myNode").Attributes("id").Remove();
酒解孤独 2024-11-18 18:32:27

您可以使用 .NET 的 XML 命名空间 加载 XML 文档,然后您可以简单地循环遍历所有元素并删除任何 ID 属性并保存结果...

...我想您也可以使用正则表达式将其从字符串中删除尽管。

You can use .NET's XML Namespace to load an XML document and then you could simply just cycle through all the element and remove any attributes that are ID's and save the result...

... I suppose you also could use a regular expression to remove it from a string though.

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