阅读使用XmlDocument的XML属性 [英] Read XML Attribute using XmlDocument

查看:256
本文介绍了阅读使用XmlDocument的XML属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用C#的XmlDocument的读取XML属性?

我有一个看起来有点像这样的XML文件:

 < XML版本=1.0编码=UTF-8&GT?;
&所述; MyConfiguration的xmlns =htt​​p://tempuri.org/myOwnSchema.xsdSuperNumber =1超弦=whipcream>
    <其他的东西/>
< / MyConfiguration>
 

我将如何读取XML属性SuperNumber和超弦理论?

目前我使用XmlDocument的,我得到的值使用的XmlDocument的的getElementsByTagName()之间的作品真的很好。我只是无法弄清楚如何获得的属性?

解决方案

  XmlNodeList中elemList = doc.GetElementsByTagName(...);
    的for(int i = 0; I< elemList.Count;我++)
    {
        。字符串attrVal = elemList [I] .Attributes [超弦理论]值;
    }
 

这是否帮助?

How can I read an XML attribute using C#'s XmlDocument?

I have an XML file which looks somewhat like this:

<?xml version="1.0" encoding="utf-8" ?>
<MyConfiguration xmlns="http://tempuri.org/myOwnSchema.xsd" SuperNumber="1" SuperString="whipcream">
    <Other stuff />
</MyConfiguration> 

How would I read the XML attributes SuperNumber and SuperString?

Currently I'm using XmlDocument, and I get the values in between using XmlDocument's GetElementsByTagName() and that works really well. I just can't figure out how to get the attributes?

解决方案

    XmlNodeList elemList = doc.GetElementsByTagName(...);
    for (int i = 0; i < elemList.Count; i++)
    {
        string attrVal = elemList[i].Attributes["SuperString"].Value;
    }  

Does this help?

这篇关于阅读使用XmlDocument的XML属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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