mardi 17 janvier 2017

How to implement line-by-line interpreter in Python?

I want to parse XML-like text file with Python. The structure is as follows:

<object begin>
    <field name 1> = value1
    ...
    <field name N> = valueN
<object end>
<object begin>
    <field name M> = valueM
    ...

The first thing to come to my mind is Chain of Responsibility, since there are many different rules of parsing for different field names. However, the business logic dictates to keep current status, because output may depend on values of several field-value pairs at once.
What classes should be implemented? Handlers read and change status, object end tag creates new status, while the old has to be written somewhere, and it all looks ugly to me.

Aucun commentaire:

Enregistrer un commentaire