XML pickle

Stefan Behnel stefan_ml at behnel.de
Fri Feb 15 09:57:19 CET 2008


castironpi at gmail.com wrote:
>> I cannot tell if the above approach will solve your problem or not.
> 
> Well, declare me a persistent object.

Ok, from now on, you are a persistent object. :)


> from lxml import etree
> 
> SS= '{urn:schemas-microsoft-com:office:spreadsheet}'
> book= etree.Element( 'Workbook' )
> book.set( 'xmlns', 'urn:schemas-microsoft-com:office:spreadsheet' )
> sheet= etree.SubElement(book, "Worksheet")
> sheet.set( SS+ 'Name', 'WSheet1' )
> table= etree.SubElement(sheet, "Table")
> row= etree.SubElement(table, "Row")
> cell1= etree.SubElement(row, "Cell")
> data1= etree.SubElement(cell1, "Data" )
> data1.set( SS+ 'Type', "Number" )
> data1.text= '123'
> cell2= etree.SubElement(row, "Cell")
> data2= etree.SubElement(cell2, "Data" )
> data2.set( SS+ 'Type', "String" )
> data2.text= 'abc'
> out= etree.tostring( book, pretty_print= True, xml_declaration=True )
> print( out )
> open( 'xl.xml', 'w' ).write( out )

http://codespeak.net/lxml/tutorial.html#namespaces
http://codespeak.net/lxml/tutorial.html#the-e-factory
http://codespeak.net/lxml/objectify.html#tree-generation-with-the-e-factory


> 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?

Stefan



More information about the Python-list mailing list