Re: XML editor using MFC



Parse the XML. As you are parsing, add elements to the tree control. Each node of the
XML tree is represented by an HTREEITEM. It should take about two hours to write this
code from scratch, except for the CDATA stuff which is a real pain to parse. If you've
never written a lexer or parser, plan on about a day.

If your XML files are < 100MB, don't even bother with reading from the disk; allocate a
buffer the size of the file and read the whole contents in at once, or use a memory-mapped
file and and map the whole file into memory. Saves a lot of nonsense about reading files,
which just gets in the way. One thing you pass into the recursion is a FILEINFO structure
of your own invention but essentially it needs to track line# and character position for
error reporting. No global variables are required; one way to be sure you are making an
error in the coding is if you use any global or static variables.

Parsing XML is trivial. You need to look for < and >, handle <name:name /> and
<name>...</name> structures, all values are of the form keyword="value", which is real
easy to parse. When you find a <, add a new node to the TreeItem you are currently
working on, and call the parser recursively.

Error recovery: simplest form, when you find an error, throw a CException-derived class,
e.g.,

throw new CXMLSyntaxError(line, character);

where line and character are file positions. It's horrible error recovery, but
sophisticated error recovery will take weeks to implement, and is nearly impossible to get
right anyway. You catch it at the topmost level surrounding the first call.

You can use different icons for the ImageList for nodes and values; in fact you need three
icons: a Node icon, a ValueName icon, and a Value icon.

If you download the code example for WIn32 programming, you can find examples of how to
drag items around in a tree view (its sort of a weird hybrid of C and MFC, but it shows
the example clearly. If you parse the DTD, you can determine what nodes are allowed to be
dragged to other nodes, but now you're talking some real investment of time, several days
at least)

Write a simple lexer using a simple FSM model. There are several examples of this on my
MVP Tips site. When you find a <, enter the parser recursively, passing in a newly-added
HTREEITEM that represents the node into which you are putting the information.
joe

On Mon, 3 Dec 2007 10:23:52 -0800 (PST), adiideas@xxxxxxxxx wrote:

Hello,

I need to develop XML editor using MFC. It needs to feature Tree View
of XML.

And have to use MFC language.

Could you please let me know any pointers?

TIA
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Convert raw data to XML
    ... you want to do is parse XML and extract data from it. ... "soup" is a tree structure representing the XML, ... is there any other way to do this without using BeautifulStoneSoup.. ...
    (comp.lang.python)
  • Re: Convert raw data to XML
    ... you want to do is parse XML and extract data from it. ... "soup" is a tree structure representing the XML, ... is there any other way to do this without using BeautifulStoneSoup.. ...
    (comp.lang.python)
  • Re: Modeling Data for XML instead of SQL-DBMS
    ... It is a tree, ... A set of XML documents may include ... DBMS tools where the link specifications are metadata. ... but I don't think that is the hierarchy you ...
    (comp.databases.theory)
  • Re: TreeView Dynamic XML Binding
    ... Subject: TreeView Dynamic XML Binding ... Expand the ReturnHeader node. ... When I click on the tree node for the select ... I'm simply trying to display the xml element tree ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: TreeView with Recursive TreeNode....
    ... > head that he was trying to output a tree in html, ... The xml would possibly give you an advantage in already ... > "Mark Broadbent" wrote in message ... >> for mirroring this in a TreeView and this is probably correct. ...
    (microsoft.public.dotnet.framework.windowsforms)