RSS Forums RSS
Please support our C# advertiser: Programming Forums
Views: 2032 | Replies: 3
Reply
Join Date: Jul 2008
Posts: 2
Reputation: asma_ab is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
asma_ab asma_ab is offline Offline
Newbie Poster

how to display XML file in textBox or Treeview using C#

  #1  
Jul 28th, 2008
hi ...
i have a query i have created an application in c# i have put this code in button

 string strXmlPath = "";
            XmlDocument doc = new XmlDocument();
            strXmlPath = ("C:/App_Data/Document.xml");
            DataSet ds = new DataSet();
            XmlTextWriter writer = new XmlTextWriter(strXmlPath,System.Text.Encoding.UTF8);

         
            writer.WriteStartElement("folder");
            writer.WriteElementString("FolderName", "App_Data");
            writer.WriteElementString("FolderPath", "C:/App_Data/Document.xml");
            writer.WriteEndElement();
           writer.WriteStartElement("folder2");
            writer.WriteElementString("FolderName", "App_Data");
            writer.WriteElementString("FolderPath", "C:/App_Data/Document.xml");
            writer.WriteEndElement();
            ds.WriteXml(@strXmlPath, System.Data.XmlWriteMode.WriteSchema);
            writer.WriteElementString("FolderName", "App_Data");
            writer.WriteElementString("FolderPath", "C/App_Data/Document.xml");
            writer.WriteEndElement();
            //XmlNode parentNode = doc.DocumentElement;
            //XmlNode bookNode = doc.CreateNode(XmlNodeType.Element, "book", null);
            //doc.AppendChild(bookNode);
            //XmlAttribute attr = doc.CreateAttribute("space");
            //attr.InnerText = "4";
            //bookNode.Attributes.Append(attr);
            // Flush

   //DisplayCatalog();
           
            writer.Close();
      
        }
but it couldnt works

i wish i could display an XML file in TextBox or TreeView plz help me out ..
Last edited by Tekmaven : Jul 28th, 2008 at 3:29 pm. Reason: Code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 52
Reputation: FaridMasood is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
FaridMasood's Avatar
FaridMasood FaridMasood is offline Offline
Junior Poster in Training

Re: how to display XML file in textBox or Treeview using C#

  #2  
Jul 30th, 2008
Hi Dear,
Here i have a suggestion for u, I am not sure if it will be useful in your case but still i am sharing. I was also wufering to open an xml file with proper formating then after googling i found that we can use the web browser control to open the xml files

I am sure that this will increase your knowledge as well.

Use the WebBorwser control and set it's navigate property it will show the file.
Be sure to pass it complete file name with directory info
such as:

"C:/App_Data/Document.xml"

Regards,
Thanks and Best of Lusk,

Farid ud din Masood
MS.c (CS)
University of Agriculture, Faisalabad
Reply With Quote  
Join Date: Jul 2008
Posts: 2
Reputation: asma_ab is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
asma_ab asma_ab is offline Offline
Newbie Poster

Re: how to display XML file in textBox or Treeview using C#

  #3  
Jul 31st, 2008
Originally Posted by FaridMasood View Post
Hi Dear,
Here i have a suggestion for u, I am not sure if it will be useful in your case but still i am sharing. I was also wufering to open an xml file with proper formating then after googling i found that we can use the web browser control to open the xml files

I am sure that this will increase your knowledge as well.

Use the WebBorwser control and set it's navigate property it will show the file.
Be sure to pass it complete file name with directory info
such as:

"C:/App_Data/Document.xml"

Regards,
Hi:
thx Masood 4 sharing ur knowlege..bt it woudnt works.....!wht else should i do.?i realy cant figure out y it wont display in listBox or treeView. do u have any other idea..
thx Best Regards.
TC
Reply With Quote  
Join Date: Nov 2006
Posts: 47
Reputation: nnobakht is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
nnobakht nnobakht is offline Offline
Light Poster

Re: how to display XML file in textBox or Treeview using C#

  #4  
Aug 13th, 2008
To display an xml in tree view or listbox i would recommend loading it into the XmlDocument class. This way you already have a tree. Then you can jsut parse through it and add what ever fields you would like and skip whatever you done want.
If you want to create a xml document the xml writer is a good class but it does allow possibilities for alot of errors for example forgetting to close and elelemt.
you can instead make the xml file using the xml writer and make the document element.
close the file and load it into the XmlDocument.
now you can just create elements and attributes easily by
XmlElement element=XmlDoc.CreateElement("name");
and set teh inner text, attributes and such from there.

look at something like this
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:56 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC