XML pickle

castironpi at gmail.com castironpi at gmail.com
Fri Feb 15 14:20:07 EST 2008


On Feb 15, 12:07 pm, castiro... at gmail.com wrote:
> On Feb 15, 11:10 am, castiro... at gmail.com wrote:
>
> > > > Can you use set( '{ss}Type' ) somehow?
>
> > > What is 'ss' here? A prefix?
>
> > > What about actually reading the tutorial?
>
> > >http://codespeak.net/lxml/tutorial.html#namespaces
>
> > > > And any way to make this look
> > > > closer to the original?
>
> > > What's the difference you experience?
>
> Something else that crept up is:
>
> <?xml version='1.0' encoding='ASCII'?>
> <Workbook xmlns="[hugethingA]">
>   <Worksheet xmlns:ns0="[hugethingA]" ns0:name="WSheet1">
>   </Worksheet>
>   <Styles>
>     <Style xmlns:ns1="[hugethingA]" ns1:ID="s21"/>
>   </Styles>
> </Workbook>
>
> Which xmlns:ns1 gets "redefined" because I just didn't figure out how
> get xmlns:ns0 definition into the Workbook tag.  But too bad for me.

In Economics, they call it "Economy to Scale"- the effect, and the
point, and past it, where the cost to produce N goods on a supply
curve on which 0 goods costs 0 exceeds that on one on which 0 goods
costs more than 0: the opposite of diminishing returns.  Does the
benefit of encapsulating the specifics of the XML file, including the
practice, exceed the cost of it?

For an only slightly more complex result, the encapsulated version is
presented; and the hand-coded, unencapsulated one is left as an
exercise to the reader.

book= Workbook()
sheet= Worksheet( book, 'WSheet1' )
table= Table( sheet )
row= Row( table, index= '2' )
style= Style( book, bold= True )
celli= Cell( row, styleid= style )
datai= Data( celli, 'Number', '123' )
cellj= Cell( row )
dataj= Data( cellj, 'String', 'abc' )

46 lines of infrastructure, moderately packed.  Note that:

etree.XML( etree.tostring( book ) )

succeeds.



More information about the Python-list mailing list