XML读取到非genericIDictionary [英] XML Read to non geneticIDictionary
本文介绍了XML读取到非genericIDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在读取XML和使用字典存储所有标签及其值时遇到问题.我在VB.Net中使用此代码没有问题.在将标签添加为键,将标签的值添加为值"的情况下失败.
I have Problem Reading XML and using dictionary to store all tags and their values.I have used this code in VB.Net without problem. It fails while "adding the tag as the key and the tag''s value as the value"
public class ConfigReader {
IDictionary dict;
public LoginConfigReader()
{
dict = new SortedList();
string myXmlFile = null;
myXmlFile = HostingEnvironment.ApplicationPhysicalPath + "App_Data\\myxmlfile.xml";
XmlTextReader reader = new XmlTextReader(myXmlFile);
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.Read(); // read the config tag
reader.Read(); // go to the first tag
while ((!reader.EOF))
{
if (!reader.IsStartElement())
{
break;
}
dict.Add(reader.Name, reader.ReadElementString); // add the tag as the key and the tag's value as the value
}
reader.Close(); //close the reader
}
推荐答案
^ ] .您应该始终尝试在Google上搜索您的问题.搜索如何将Xml Document C#读取到字典中"返回了158万个结果.第一页为您提供了潜在的解决方案.干杯.
Lots of options.[^]. You should always attempt a search on google of your question. The search "How to read Xml Document C# to dictionary" returned 1.58 million results. The first page is full of potential solutions for you. Cheers.
这篇关于XML读取到非genericIDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文