Re: [xml] What is the advantage of a Reader vs a Parser?

BJ Chippindale wrote:

It also appears that if the XML is a control message in which the
meaning of lower levels depends on the context set in upper ones, the
reader is inconvenient.  Message "state" information has to be retained
and/or discarded for each node as it is processed.  For example:  An
address that is a "destination" is not treated the same as a "source"
but the node name is identical. So I have to retain state information
throughout the processing and it quickly becomes intractably dense code
(Which is why I started exploring the parsing in the first instance). It appears that the standard parsing model is better suited to this sort of work, as the context is implicit in the position on the tree.

This is classic state-machine programming, and you are right, it is more work up front than using an XML "parser". However, if the documents you are dealing with are large enough for memory consumption to matter, it can make a large difference in the app's memory usage.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]