Writing big XML files where beginning depends on end.

Gerard Flanagan grflanagan at yahoo.co.uk
Sat Nov 26 06:33:17 CET 2005


Magnus Lycka wrote:

> We're using DOM to create XML files that describes fairly
> complex calculations. The XML is structured as a big tree,
> where elements in the beginning have values that depend on
> other values further down in the tree. Imagine something
> like below, but much bigger and much more complex:
>
> <node sum="15">
>      <node sum="10">
>          <leaf>7</leaf'>
>          <node sum="3">
>              <leaf>2</leaf'>
>              <leaf>1</leaf>
>          </node>
>      </node>
>      <node sum="5">
>          <leaf>5</leaf>
>      </node>
> </node>
>
> We have to stick with this XML structure for now.

>
> We've thought of writing a file that looks like this...
>
> <node sum="#1">
>      <node sum="#1.1">
>          <leaf>7</leaf'>
>          <node sum="#1.1.1">
>              <leaf>2</leaf'>
>              <leaf>1</leaf>
>          </node>
>      </node>
>      <node sum="#1.2">
>          <leaf>5</leaf>
>      </node>
> </node>
>
> ...and store {"#": "15", "#1.1", "10" ... } in a map
> and then read in a piece at a time and performs some
> simple change and replace to get the correct values in.
> Then we need something that allows parts of the XML file
> to be written to file and purged from RAM to avoid the
> memory problem.
>
> Suggestions for solutions are appreciated.

Magnus

what about multiple xml files?  Then any given node could have a value
"2.3.xml" which is loaded on demand.
Or, IANA Computer Scientist, but isn't every tree a list?  Then maybe
flatten/unflatten nodes to a string representation

eg. { "#1" : 15, "#1.1" : "[ 10 [7] [3 [2][1] ] ]", "#1.2" : "[ [5] ]"
}

Hope this isn't too naive.

Gerard




More information about the Python-list mailing list