Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 16-Feb-13 5:37am
v2
Comments
Muthuraja Irullandi at 16-Feb-13 11:54am
   
Hi,
Can you share your XML file structure?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
Maciej Los at 16-Feb-13 12:49pm
   
My 5!
Sandeep Mewara at 16-Feb-13 13:40pm
   
Thanks Maciej. :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

      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);
         }
         
      }
   }
 
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 370
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 235
3 Afzaal Ahmad Zeeshan 209
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100