阅读使用XmlDocument的XML属性属性、XmlDocument、XML

2023-09-02 10:17:35 作者:卖萌症丶

我如何使用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 [超弦理论]值;
    }
 
如何查看rss源的xml属性

这是否帮助?

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?