Link to home
Create AccountLog in
Avatar of NewMom2Brandon
NewMom2Brandon

asked on

XML reading help(urgent)

Here is my xml file

<Config>
<PI>
   <Id value="1" />
   <Con>
      <Type value="text" />
   </Con>
 </PI>
</Config>

The XML file loads fine. However when I try ti access the value from the node. I get nothing. I need to get the word text from the Type. What am I doing wrong or missing.

         // Load XML document, loads into memory
         XmlDocument xmlDoc = new XmlDocument();
         try
         {
            xmlDoc.Load(sConfigFile);
         }
         catch (Exception ex)
         {
            System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "Error XML reading" + ex.ToString(),
               System.Diagnostics.EventLogEntryType.Error);
         }

         //read the document and pull the node into the Text box
         try
         {

            XmlNode TypeNode = xmlDoc.SelectSingleNode
           ("/Config/PI/Con/Type");
            string Type = TypeNode.InnerText;
            MessageBox.Show("results: " + Type, Text);
         }
         catch (Exception ex)
         {
            System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "Error XML reading" + ex.ToString(),
               System.Diagnostics.EventLogEntryType.Error);
         }
ASKER CERTIFIED SOLUTION
Avatar of e1v
e1v

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of NewMom2Brandon
NewMom2Brandon

ASKER

Yep it works. Thank you so much