Adding upstream version 1.8.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
c48d95b7fa
commit
e40b3259c1
2403 changed files with 153656 additions and 0 deletions
examples
54
examples/xmlDemo.py
Executable file
54
examples/xmlDemo.py
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python3
|
||||
'Demo script for use of ETWriter'
|
||||
__url__ = 'https://github.com/silnrsi/pysilfont'
|
||||
__copyright__ = 'Copyright (c) 2015 SIL International (https://www.sil.org)'
|
||||
__license__ = 'Released under the MIT License (https://opensource.org/licenses/MIT)'
|
||||
__author__ = 'David Raymond'
|
||||
|
||||
from silfont.core import execute
|
||||
import silfont.etutil as etutil
|
||||
from xml.etree import cElementTree as ET
|
||||
|
||||
argspec = [('outfile1',{'help': 'output file 1','default': './xmlDemo.xml','nargs': '?'}, {'type': 'outfile'}),
|
||||
('outfile2',{'help': 'output file 2','nargs': '?'}, {'type': 'outfile', 'def':'_2.xml'}),
|
||||
('outfile3',{'help': 'output file 3','nargs': '?'}, {'type': 'outfile', 'def':'_3.xml'})]
|
||||
|
||||
def doit(args) :
|
||||
ofile1 = args.outfile1
|
||||
ofile2 = args.outfile2
|
||||
ofile3 = args.outfile3
|
||||
|
||||
xmlstring = "<item>\n<subitem hello='world'>\n<subsub name='moon'>\n<value>lunar</value>\n</subsub>\n</subitem>"
|
||||
xmlstring += "<subitem hello='jupiter'>\n<subsub name='moon'>\n<value>IO</value>\n</subsub>\n</subitem>\n</item>"
|
||||
|
||||
# Using etutil's xmlitem class
|
||||
|
||||
xmlobj = etutil.xmlitem()
|
||||
xmlobj.etree = ET.fromstring(xmlstring)
|
||||
|
||||
etwobj = etutil.ETWriter(xmlobj.etree)
|
||||
xmlobj.outxmlstr = etwobj.serialize_xml()
|
||||
|
||||
ofile1.write(xmlobj.outxmlstr)
|
||||
|
||||
# Just using ETWriter
|
||||
|
||||
etwobj = etutil.ETWriter( ET.fromstring(xmlstring) )
|
||||
xmlstr = etwobj.serialize_xml()
|
||||
ofile2.write(xmlstr)
|
||||
# Changing parameters
|
||||
|
||||
etwobj = etutil.ETWriter( ET.fromstring(xmlstring) )
|
||||
etwobj.indentIncr = " "
|
||||
etwobj.indentFirst = ""
|
||||
xmlstr = etwobj.serialize_xml()
|
||||
ofile3.write(xmlstr)
|
||||
|
||||
# Close files and exit
|
||||
ofile1.close()
|
||||
ofile2.close()
|
||||
ofile3.close()
|
||||
return
|
||||
|
||||
def cmd() : execute("",doit,argspec)
|
||||
if __name__ == "__main__": cmd()
|
Loading…
Add table
Add a link
Reference in a new issue