我在 XmlDocument
中有以下 xml。我正在尝试从中提取 className
。
<Registration className="Eng" type="DirectRegistration" state="Activated" xmlns="http://xyz/Registration">
<Fields>
<Field type="abc" value="123456" />
<Field type="xyz" value="789" />
</Fields>
</Registration>
我试过下面的代码,但它没有给我 className
。
var xmlNode = xmlDoc.DocumentElement;
谁能帮我把 className
的值取出来。
非常感谢
最佳答案
你快到了:
var className = xmlDoc.DocumentElement.GetAttribute("className");
xmlDoc.DocumentElement
为您提供了 whole 元素; GetAttribute
从中提取一个单独的命名属性。
关于c# - 如何从 xml 中检索属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11950562/