Click here to Skip to main content
15,923,006 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI Team,

I have one XML File "FormData" , which has few parameters like "Name ", "City", "ContactNo".

Now, I have to show those XML file details into Textboxes .

How to read and show in Textbox.

Please tell me this concept.

Regards,

Rakesh
Posted
v2
Comments
Muthuraja Irullandi 16-Feb-13 11:54am    
Hi,
Can you share your XML file structure?

Easiest way would be to use XPath.

Details here:
MSDN:XPath Examples[^]
XPath - Elements and Attributes[^]

Somewhat question type article: Manipulate XML data with XPath and XmlDocument (C#)[^]

Try!
 
Share this answer
 
Comments
Maciej Los 16-Feb-13 12:49pm    
My 5!
Sandeep Mewara 16-Feb-13 13:40pm    
Thanks Maciej. :)
      static void Main(string[] args)
      {
         try
         {
            // Create an XML document instance.
            
            XmlDocument doc = new XmlDocument();

            // Load the XML data from a file.
            // This code assumes that the XML file is in the same folder.
            // the /bin/debug file of your project 

            doc.Load("Q317662.xml");  

XmlNodeList list = doc.GetElementsByTagName(string name)

for each (XmlNode item in list){
txtTextBoxOfYourChoise.Text = item.innerChild.value.ToString(); 
// or what ever you want in those text boxes 
}
             

         
         }
         catch(XmlException xmlEx)   // Handle the XML exceptions here.   
         {
            Console.WriteLine("{0}", xmlEx.Message);
         }
         catch(Exception ex)         // Handle the generic exceptions here.
         {
            Console.WriteLine("{0}", ex.Message);
         }
         
      }
   }

}
 
Share this answer
 
v2
Here are the ways you can parse XML with .NET:


  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].


—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900