Click here to Skip to main content
15,909,591 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am building an application which will open an XML file and perform some actions.

I want an solution for following Question then only i can go ahead for advance features.

I am able to open XML file in RichTextBox as follow but its opening as Simple notepad file i want it in format of XML editors software like element, attribute highlighted.

Please help me on this.

If anyone having code with OpenFiledialog and XML classes then it will be the best.

Thnaks and Regards,

Mayur Alaspure

C#
private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {



            OpenFileDialog OpenFDB = new OpenFileDialog();
            OpenFDB.InitialDirectory = "@C:\\My Documnets\\";
            OpenFDB.Filter = "xml Files|*.xml|html Files|*.html|All Files|*.*";
            OpenFDB.FilterIndex = 3;
            if (OpenFDB .ShowDialog() == DialogResult .OK)
            {
                try
                {
                    MainRTB.LoadFile(OpenFDB.FileName,RichTextBoxStreamType.PlainText );

                }
                catch (Exception exp)
                {
                    MessageBox.Show("An error occurred : "+ System.Environment .NewLine + exp .ToString() +System .Environment.NewLine  );

                    throw;
                }


            }
        }
Posted
Comments
Sandeep Mewara 27-May-12 3:11am    
Can you elaborate a little more: but its opening as Simple notepad file i want it in format of XML editors software like element, attribute highlighted
Mayur2258 27-May-12 8:03am    
Hi sandeep I want to open XML file like a XML editor. The view of XML elements, attributes and attribute values should be highlighted in different colors.

Are you looking for a text editor with syntax highlight? You probably need: Scintilla.net[^]
 
Share this answer
 
Comments
Mayur2258 28-May-12 4:17am    
Hi Thanks for your support,

Can you just give me the demo how to use this?

This seems to be interesting to learn something new for me. :)
Zoltán Zörgő 28-May-12 8:40am    
You have a sample app on the site: http://scintillanet.codeplex.com/downloads/get/360979
Mayur2258 28-May-12 21:39pm    
Thanks a lot buddy but still my Question is not solved i want to create it my self using simple OpenFileDialogBox, RichTextBox. I want to open the XML file using this OpenFileDialogBox in RichTxtBox which i have done but its simple showing as text file. I want to highlight markups. suggest the code for it.
Zoltán Zörgő 29-May-12 5:40am    
Well, have you googled for it? Look here and here
VJ Reddy 3-Jun-12 10:26am    
Good references. 5!
If you want only to visualize the xml with syntax highlighting you can start here:
XML Visualizer v.2[^]
XML Explorer[^]
This is an editor too:
XML Editor Control[^]
 
Share this answer
 
Comments
VJ Reddy 7-Jun-12 5:16am    
Good references. 5!
The references given in Solution 1 by Zoltán Zörgő are good.

As an alternative the component given in this CodeProject article, Fast Colored TextBox for Syntax Highlighting[^] can be tried.

In the example given at the above article the Syntax highlighting for C#, VB, HTML, SQL, PHP were shown. Further, there is an option in the code to set the syntax highlighting for other requirements. So, the required syntax settings for the XML can be given in the above component on the similar lines of HTML syntax highlighting already given in the example.

It is mentioned in the article that
".... component inherited from RichTextBox, but while using it for a large amount of text I found out that RichTextBox highlights very slowly a large number of colored fragments (from 200 and more). .... Therefore I created my own text component which uses neither Windows TextBox nor RichTextBox........... possesses tools to make comfortably dynamic syntax highlighting."
 
Share this answer
 
v3
Comments
Mayur2258 3-Jun-12 22:32pm    
Thanks VJ Reddy

I had read this article before, tut I am kindly telling i am fresher in Programming and I am facing difficulties to understanding this coding. So i am searching for the reference Where an XML file is simply open by RichTextBox and the syntax are highlighted.

But now an thinking to solve this problem using System.Xml class is there any way using this class. ?

your suggestions will help me lot. :)

Thanks and regards,
Mayur Alaspure
Zoltán Zörgő 5-Jun-12 5:52am    
System.Xml is for manipulation XML not visualizing or editing it. If you need only visualization, there are some more options if you do't stick to RichTextBox. See my other answer.
Hi you all,

Thanks for your reply's. :)

While searching the answer for the same question, I found the simplest code here:

Only the difference is, It is created in WPF but its really small and helpful.

A Simple WPF XML Document Viewer Control[^]


Regards,

Mayur Alaspure
 
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