XmlDocument.Attributes
perhaps? (Which has a method GetNamedItem that will presumably do what you want, although I've always just iterated the attribute collection)
jerryjvl
2009-06-01 05:53:48
XmlDocument.Attributes
perhaps? (Which has a method GetNamedItem that will presumably do what you want, although I've always just iterated the attribute collection)
XmlNodeList elemList = doc.GetElementsByTagName(...);
for (int i = 0; i < elemList.Count; i++)
{
string attrVal = elemList[i].Attributes["SuperString"].Value;
}
Is this helps?
You should look into XPath. Once you start using it, you'll find its a lot more efficient and easier to code than iterating through lists. It also lets you directly get the things you want.
Then the code would be something similar to
string attrVal = doc.SelectSingleNode("/MyConfiguration/@SuperNumber").Value;
You can migrate to XDocument instead of XmlDocument and then use Linq if you prefer that syntax. Something like:
var q = (from myConfig in xDoc.Elements("MyConfiguration")
select myConfig.Attribute("SuperString").Value)
.First();