Skip to content

Commit 8243c01

Browse files
added example for xml handling
1 parent 23a2739 commit 8243c01

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

examples/document.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from modelspec import field, instance_of, optional
33
from modelspec.base_types import Base
44
from typing import List
5+
from modelspec.utils import save_to_xml_file
56

67
# Example showing how to create a model of a document and use it to create/serialize instances
78

@@ -70,10 +71,12 @@ class Document(Base):
7071
doc.to_json_file("document.json")
7172
doc.to_yaml_file("document.yaml")
7273
doc.to_bson_file("document.bson")
74+
doc.to_xml_file("document.xml")
7375

7476
print(" >> Full document details in YAML format:\n")
7577

7678
print(doc.to_yaml())
79+
print(doc.to_xml())
7780

7881
doc_md = doc.generate_documentation(format="markdown")
7982

@@ -106,3 +109,5 @@ class Document(Base):
106109

107110
with open("document.specification.bson", "wb") as d:
108111
d.write(bson.encode(doc_dict))
112+
113+
save_to_xml_file(doc_dict,"document.specification.xml")

0 commit comments

Comments
 (0)