本文介绍了新手试图读取XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经在.xml文件中写了一堆共享设置而我正在尝试将它们读回来,不过我是我只获得第一个电子邮件地址和启用设置。 XML如下所示: < SharedSettings > < 电子邮件 > < eMailAddress > [email protected] < / eMailAddress > < eMailAddress > [email protected] < / eMailAddress > < eMailAddress > [email protected]< / eMailAddress > < eMailAddress / > < eMailAddress / > < eMailAddress / > < eMailAddress / > < eMailAddress / > < eMailAddress / > < eMailAddress / > < eMailEnabled > True < / eMailEnabled > < eMailEnabled > 错误< / eMailEnabled > < eMailEnabled > 错误< / eMailEnabled > < eMailEnabl ed > False < / eMailEnabled > < eMailEnabled > False < / eMailEnabled > < eMailEnabled > False < / eMailEnabled > < eMailEnabled > False < / eMailEnabled > < eMailEnabled > False < / eMailEnabled > < eMailEnabled > False < / eMailEnabled > < eMailEnabled > False < / eMailEnabled > < / eMail > < / SharedSettings > 和代码I用于阅读设置如下: xmlDoc = new XmlDocument(); xmlDoc.Load(@ GetSet.path + @ \ SharedSettings.xml) ; XmlNodeList xnList = xmlDoc.SelectNodes( / SharedSettings / eMail) ; x = 1 ; foreach (XmlNode xn in xnList) { string eMailAddress [x] = xn [ eMailAddress]的innerText; bool bEmail [x] = Convert.ToBoolean(xn [ eMailEnabled]的innerText)。 x ++; } 查看xn中的Count它显示为一个。我是XML的新手,并没有看到我做错了什么。 XML错了还是我读错了?你有一个如何做到这一点的例子吗? 谢谢你, 格伦解决方案 Hi,I have written a bunch of "Shared Settings" out to an .xml file and I'm trying to read them back, however I'm only getting the first email address and enabled setting. The XML looks like this:<SharedSettings><eMail> <eMailAddress>[email protected]</eMailAddress> <eMailAddress>[email protected]</eMailAddress> <eMailAddress>[email protected]</eMailAddress> <eMailAddress/> <eMailAddress/> <eMailAddress/> <eMailAddress/> <eMailAddress/> <eMailAddress/> <eMailAddress/> <eMailEnabled>True</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> <eMailEnabled>False</eMailEnabled> </eMail></SharedSettings>and the code I'm using to read the settings looks like this:xmlDoc = new XmlDocument();xmlDoc.Load(@GetSet.path + @"\SharedSettings.xml");XmlNodeList xnList = xmlDoc.SelectNodes("/SharedSettings/eMail");x = 1;foreach (XmlNode xn in xnList){ string eMailAddress[x] = xn["eMailAddress"].InnerText; bool bEmail[x] = Convert.ToBoolean(xn["eMailEnabled"].InnerText); x++;}Looking at the Count in "xn" it shows as one. I'm new to XML and don't see what I've done wrong. Is the XML wrong or am I reading it wrong? Do you have an example of how to do this?Thank you,Glenn 解决方案 这篇关于新手试图读取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 09:09