XML question, DOM or SAX?

Markus von Ehr markus.vonehr at ipm.fhg.de
Fri Oct 18 12:07:31 EDT 2002


Hi,

when I use the statement:

 <spectrum values="0.1 0.2 0.14"/>

and I read the XML-file, do I get a node for the whole line
conaining the 1000 values and do I have to separate a string
with something lie: string.split(s, " ") ?

Markus


Harvey Thomas schrieb:
> 
> Markus von Ehr wrote:
> >
> > Hi Gustavo,
> >
> > no, I don't have rgb values, inside one spec I have about 1000
> > values representing spectral lines.
> > I don't want to enclose every value inside something like
> > <red>
> > </red>
> > the efficiency would be very bad...
> >
> > Markus
> >
> >
> > sismex01 at hebmex.com schrieb:
> > >
> > > > 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
> > --
> 
> I think you might have to give us a bit more information about what you want to store.
> Note that an XML file must have only one root element. From the example you gave you
> could store your data as follows:
> <spectra>
> <spectrum values="0.1 0.2 0.14"/>
> <spectrum values="0.2 0.3 0.11"/>
> <spectrum values="0.14 0.17 0.12"/>
> </spectra>
> 
> _____________________________________________________________________
> This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.



More information about the Python-list mailing list