在C#和RichTextBox中打开XML文件 [英] Opening XML file in C# and RichTextBox

查看:277
本文介绍了在C#和RichTextBox中打开XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在构建一个将打开XML文件并执行一些操作的应用程序.

我想要解决以下问题的方法,然后只有我才能继续使用高级功能.

我可以按照以下步骤在RichTextBox中打开XML文件,但可以将其作为简单记事本文件打开,我希望它以XML编辑器软件的格式(例如元素,属性突出显示)打开.

请帮助我.

如果有人使用OpenFiledialog和XML类编写代码,那将是最好的.

致谢和问候,

Mayur Alaspure

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

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;
                }


            }
        }

推荐答案

您是否正在寻找带有语法高亮显示的文本编辑器?您可能需要: Scintilla.net [ ^ ]
Are you looking for a text editor with syntax highlight? You probably need: Scintilla.net[^]


如果您只想通过语法高亮显示xml,则可以从这里开始:
XML Visualizer v.2 [ XML资源管理器 [ XML编辑器控件 [
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[^]


解决方案1中的引用由ZoltánZörgő 很好.

作为此CodeProject文章中给出的组件的替代,
用于语法突出显示的彩色文本框 [ ^ ]可以尝试.

在以上文章给出的示例中,显示了C#, VB, HTML, SQL, PHP的语法突出显示.此外,代码中有一个选项可以为其他要求设置语法突出显示.因此,可以在上述组件中的示例中已经给出的HTML 语法高亮的类似行中,给出XML 所需的语法设置.

文章中提到
"....组件继承自RichTextBox,但是在将其用于大量文本时,我发现RichTextBox会非常缓慢地突出显示大量彩色片段(从200个以上).....因此,我创建了我自己的文本组件,该组件既不使用Windows TextBox也不使用RichTextBox ......拥有能够轻松进行动态语法高亮显示的工具."
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."


这篇关于在C#和RichTextBox中打开XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆