Python to XML to Python conversion
Jeremy Bowers
newfroups at jerf.org
Fri Jul 12 11:53:45 EDT 2002
Jeremy Bowers wrote:
> Alex Martelli wrote:
>> I think this assertion, as it stands, is untenable. There just about
>> IS *some* other way -- e.g., inventing your own little language for
>> data description and writing from scratch the needed parsers in all
>> languages and environments of interest.
>
>
> That's order N effort rather then constant effort, thus that's not easy
> parsing in other environments, that's the virtually impossible job we
> were faced with 10 years ago. (SGML wasn't all that easy either, from
> what I gather.)
Though it occurs to me to point out a bit later that parsing somebody
else's XML format can feel about as hard as parsing a new little
language; XML libraries take care of the tokenizing and parsing step but
you still get to do the semantic analysis yourself. If you're good with
writing parsers (which usually implies tokenizing is a non-issue to that
person), this can be a bad tradeoff if you could write a much simpler
special-purpose language that would tokenize and parse into something
more closely appropriate to the task at hand. Sometimes straight into
the desired format; I, and others, have used Python source code files
directly as configuration files before. Parsing an XML-version of those
files is a pain, relative to the eas of 'parsing' the Python
configuration file:
from configuration import *
or
import configuration
Complete with robust error detection.
Part of the reason XML is useful is that programmers who have not
dedicated their lives to writing compilers find it easier to muddle
through the semantic analysis then to write a good tokenizer and parser,
as the latter largely *can't* be muddled through for any non-trivial
language. (Parsers are powerful but do like to bite hard.)
Of course, other reasons include the fact that this tokenizer/parser is
available in multiple languages, reasonably human readable, etc. This
message is an observation and food for though, not the whole of my XML
views. I may not even agree with this observation tommorow. ;-)
More information about the Python-list
mailing list