删除 xml 文档中存在的属性
如果文档中存在属性,如何从 XmlDocument 中删除该属性?请帮忙。我正在使用RemoveAttribute,但如何检查它是否存在。
root.RemoveAttribute(fieldName);
谢谢..
<?xml version="1.0" standalone="yes" ?>
<Record1>
<Attribute1 Name="DataFieldName" Value="Pages" />
</Record1>
我正在尝试删除名为“DataFieldName”的属性。
How to remove the attribute from XmlDocument if attribute exists in the document? Please help. I am using RemoveAttribute but how can I check if it exists.
root.RemoveAttribute(fieldName);
Thanks..
<?xml version="1.0" standalone="yes" ?>
<Record1>
<Attribute1 Name="DataFieldName" Value="Pages" />
</Record1>
I am trying to remove attribute named "DataFieldName".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定你到底想做什么,所以这里有两个例子。
删除属性:
将属性设置为空字符串:
编辑:如果您详细说明原始请求,我可以尝试修改我的代码。一个 XML 文档只能有一个根节点,您的根节点似乎是 record1。那么这是否意味着您的整个文件将只包含一条记录?或者你的意思是有类似的东西
Not sure exactly what you're trying to do, so here's two examples.
Removing the attribute:
Setting the attribute to an empty string:
Edit: I can try to modify my code if you elaborate on your original request. An XML document can only have one root node and yours appears to be record1. So does that mean your entire file will only contain a single record? Or did you mean to have something like
您可以使用 XmlNamedNodeMap.RemoveNamedItem 方法(名称)来执行此操作。它可用于 Attributes。如果未找到匹配的节点,它将返回从此 XmlNamedNodeMap 中删除的 XmlNode 或空引用(在 Visual Basic 中为 Nothing)。
youcan use XmlNamedNodeMap.RemoveNamedItem Method (name) to do it. It can be used to Attributes.It will return the XmlNode removed from this XmlNamedNodeMap or a null reference (Nothing in Visual Basic) if a matching node was not found.