954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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 ..

asma_ab
Newbie Poster
2 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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,

FaridMasood
Junior Poster in Training
59 posts since Mar 2007
Reputation Points: 8
Solved Threads: 0
 

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

asma_ab
Newbie Poster
2 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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

nnobakht
Light Poster
47 posts since Nov 2006
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You