Вопрос

Hi I have a xml in my Windows forms application. I am tring to get a node value. It is pretty basic and a lot of ways to get it I know but the wuestion is my xml not even loading. When I debug, after this line

xml.LoadXml(xmlPath);

program refuses to go to next line at all.Here is my full code.

XmlDocument xml = new XmlDocument();
string xmlPath = "settings.xml";
xml.LoadXml(xmlPath);
txtPass.Text = xml.SelectSingleNode("settings/user-settings/pass").InnerText.ToString();

Edit : I also tried xml.Load() but I have the same issue.

Это было полезно?

Решение 2

Xml file name is "CompSpecs"

{
                        string path = @"";
                        FileStream READER = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Set up the filestream (READER) //
                        System.Xml.XmlDocument CompSpecs = new System.Xml.XmlDocument();// Set up the XmlDocument (CompSpecs) //
                        CompSpecs.Load(READER); //Load the data from the file into the XmlDocument (CompSpecs) //
                        System.Xml.XmlNodeList NodeList = CompSpecs.GetElementsByTagName("CompSpecs"); 
                        textBox1.Text = NodeList[0].FirstChild.NextSibling.ChildNodes[0].InnerText; 
}

My XML FILE IS

<?xml version="1.0" ?> 
- <CompSpecs>
- <CP>
  <Type>intel Hp Core2DU</Type> 
  <RAM>4GBszz</RAM> 
  <CPU_Speed>3.8Ghz</CPU_Speed> 
  </CP>
- <CP>
  <Type>intel dell</Type> 
  <RAM>4GB</RAM> 
  <CPU_Speed>3.8Ghz</CPU_Speed> 
  </CP>
  </CompSpecs>

Другие советы

That's because LoadXml is not meant to load files but XML content.

Source

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top