XML question, DOM or SAX?

sismex01 at hebmex.com sismex01 at hebmex.com
Fri Oct 18 10:51:18 EDT 2002


> From: Markus von Ehr [mailto:markus.vonehr at ipm.fhg.de]
> 
> Hi,
> 
> 1.
> I want to save one or more spectras in a XML file.
> The program shall be able to read this file into my own
> data object structure, too.
> The data can be displayed or altered.
> After all the data has to be saved again to XML.
> 
> Shall I use SAX or DOM?
> 
> 2.
> One file can contain one or more spectra.
> Can the structure be like that?
> <spec>
>  0.1
>  0.2
>  0.14
> </spec>
> <spec>
>  0.2
>  0.3
>  0.11
> </spec>
> <spec>
>  0.14
>  0.17
>  0.12
> </spec>
> 
> or is it impossible to enclose all values from one spectra within
> the <spec> quotation?
> 
> Thanks for any hints,
> 
> Markus
>

I suppose that the number triad is r,g,b values; but without any
markup it's impossible to know.

One you've read a spec, you'd have to split on whitespace, and
then convert to numbers; your application, internally, has to know
in what order the values are (rgb, ycm, hsv, etc), else it can't
tell them apart.

I'd rather use something a bit more verbose, but impossible to
confuse or musunderstand; either encode in attributes:

    <spec red="0.1" green="0.2" blue="0.14" />
    <spec red="0.2" green="0.3" blue="0.11" />
    <spec red="0.14" green="0.17" blue="0.12" />

or, encode in nested tags:

    <spec>
      <red>0.1</red>
      <green>0.2</green>
      <blue>0.14</blue>
    </spec>
    <spec>
      <red>0.2</red>
      <green>0.3</green>
      <blue>0.11</blue>
    </spec>
    <spec>
      <red>0.14</red>
      <green>0.17</green>
      <blue>0.12</blue>
    </spec>

You can also add an "encoding" tag, to indicate which
tags can be found inside:

    <spec encoding="rgb"> .... </spec>
    <spec encoding="cmyk"> .... </spec>

etc.

Anyway, that's just my opinion; hope this helps.

good luck :-)

-gustavo





More information about the Python-list mailing list