Changeset 4046
- Timestamp:
- 2 Apr 2009, 11:05:28 (16 years ago)
- Location:
- waeup/branches/ulif-rewrite/src/waeup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/README.txt
r4041 r4046 69 69 70 70 >>> print f.read() 71 <?xml version="1.0" encoding="UTF-8"?>... 72 71 <?xml version="1.0" encoding="utf-8" ?> 72 <pickle> 73 <initialized_object> 74 ... 75 </pickle> 73 76 74 77 -
waeup/branches/ulif-rewrite/src/waeup/utils/importexport.txt
r4042 r4046 24 24 One of the major formats we support for data export is XML. 25 25 26 When we want to export an object, we can choose the kind of XML to27 generate (plain or pretty) and the destination file. If we do not give 28 a file to write to, we get a StringIO object,i.e. an in-memory file.26 When we want to export an object, we can choose the destination 27 file. If we do not give a file to write to, we get a StringIO object, 28 i.e. an in-memory file. 29 29 30 30 To show this basic functionality provided for all XML exportable … … 56 56 57 57 >>> print result.read() 58 <?xml version="1.0" encoding=" UTF-8"?>...58 <?xml version="1.0" encoding="utf-8" ?>... 59 59 60 61 Exporting pretty XML62 --------------------63 64 As the result is one long string (which is necessary to preserve65 linebreaks), it is not very good readable. This special exporter66 however, can also provide ``pretty XML``::67 68 >>> print exporter.exportPrettyXML(myfaculty).read()69 <?xml version="1.0" encoding="UTF-8"?>70 <waeupdata>71 <object type="waeup.university.faculty.Faculty">72 <attribute name="name" type="str">73 My very faculty.74 </attribute>75 </object>76 </waeupdata>77 60 78 61 Generating XML files 79 62 -------------------- 80 63 81 Both methods (`export` and `exportPrettyXML`) support writing the 82 results to a file:: 64 We can also let the results be written to a file:: 83 65 84 66 >>> result = exporter.export(myfaculty, 'myexport.xml') 85 67 >>> print open('myexport.xml', 'rb').read() 86 <?xml version="1.0" encoding="UTF-8"?>... 87 88 We can also let the exporter format the output prettier:: 89 90 >>> result = exporter.exportPrettyXML(myfaculty, 'myexport.xml') 91 >>> print open('myexport.xml', 'rb').read() 92 <?xml version="1.0" encoding="UTF-8"?> 93 <waeupdata> 94 <object type="waeup.university.faculty.Faculty"> 95 <attribute name="name" type="str"> 96 My very faculty. 97 </attribute> 98 </object> 99 </waeupdata> 68 <?xml version="1.0" encoding="utf-8" ?> 69 <pickle> 70 <initialized_object> 71 ... 72 </pickle> 100 73 101 74 Clean up::
Note: See TracChangeset for help on using the changeset viewer.