Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / XML

XML Editor

4.63/5 (9 votes)
25 Oct 20052 min read 1   6.1K  
XML Editor with intellisense, automatic tag completion and parsing etc...

Screen Shot 1

Introduction

I have read and downloaded many articles and source code from CodeProject, and now I am trying to payback. Recently I had to develop a small and simple XML editor for a data conversion company. We shall discuss the scenario here.

Before I start, I just want to say that I am a new kid in .NET and the contents of this article/source code are not very professional, it is only for beginners. You may have better or simple ways to establish these goals. Anyway I would love to hear from you. I am very much interested in improving my skills. So, if you have any comments, please drop me a mail or post a feedback.

What is an XML Editor?

As far as I know, an XML editor should have all the necessary functionalities of a text editor, plus some extra functionalities like parsing, Intellisense (showing available tags when user types the '<' symbol), output viewing etc.

How?

To fetch available elements and attributes of XML document, we need to read DTD/Schema (Here I am using DTD). Regular Expression is the easiest way to establish this task, just read DTD using StreamReader and extract elements and attributes using Regular Expression and store them in a DataTable.

In XML, we have elements and attributes. What we want is, when a user presses '<' it should pop a list of elements and the selected tag should be inserted at that location. When the user presses '<' and the '/' symbol, the last opened tag should be closed automatically. This can be done by using the Stack class (which provides a simple last-in-first-out collection of objects).

Screen Shot

Next we want to format the XML file with proper indentation. Here also I use Regular Expressions to solve the issue. Browse the source code for details, it is almost self-describing. Parsing is the next issue, you can do this by simply importing the XML assembly and using the XmlValidatingReader class.

Happy coding....

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here