File tree Expand file tree Collapse file tree 4 files changed +28
-13
lines changed
docs/sphinx/source/api/examples Expand file tree Collapse file tree 4 files changed +28
-13
lines changed Original file line number Diff line number Diff line change 2
2
from modelspec import field , instance_of , optional
3
3
from modelspec .base_types import Base
4
4
from typing import List
5
+ import sys
5
6
6
7
# Example showing how to create a model of a document and use it to create/serialize instances
7
8
@@ -69,13 +70,16 @@ class Document(Base):
69
70
70
71
doc .to_json_file ("document.json" )
71
72
doc .to_yaml_file ("document.yaml" )
73
+ print (" >> Full document details in YAML format:\n " )
74
+ print (doc .to_yaml ())
75
+
72
76
doc .to_bson_file ("document.bson" )
73
- doc .to_xml_file ("document.xml" )
74
77
75
- print (" >> Full document details in YAML format:\n " )
78
+ if sys .version_info >= (3 , 8 ):
79
+ doc .to_xml_file ("document.xml" )
80
+ print (" >> Full document details in XML format:\n " )
81
+ print (doc .to_xml ())
76
82
77
- print (doc .to_yaml ())
78
- print (doc .to_xml ())
79
83
80
84
doc_md = doc .generate_documentation (format = "markdown" )
81
85
Original file line number Diff line number Diff line change 2
2
from modelspec import field , instance_of , optional
3
3
from modelspec .base_types import Base
4
4
from typing import List
5
+ import sys
5
6
6
7
# Example showing how to create a model of a document and use it to create/serialize instances
7
8
@@ -69,13 +70,16 @@ class Document(Base):
69
70
70
71
doc .to_json_file ("document.json" )
71
72
doc .to_yaml_file ("document.yaml" )
73
+ print (" >> Full document details in YAML format:\n " )
74
+ print (doc .to_yaml ())
75
+
72
76
doc .to_bson_file ("document.bson" )
73
- doc .to_xml_file ("document.xml" )
74
77
75
- print (" >> Full document details in YAML format:\n " )
78
+ if sys .version_info >= (3 , 8 ):
79
+ doc .to_xml_file ("document.xml" )
80
+ print (" >> Full document details in XML format:\n " )
81
+ print (doc .to_xml ())
76
82
77
- print (doc .to_yaml ())
78
- print (doc .to_xml ())
79
83
80
84
doc_md = doc .generate_documentation (format = "markdown" )
81
85
Original file line number Diff line number Diff line change 2
2
from modelspec import field , instance_of , optional
3
3
from modelspec .base_types import Base
4
4
from typing import List
5
+ import sys
5
6
6
7
# Example showing ...
7
8
@@ -147,13 +148,15 @@ class neuroML(Base):
147
148
148
149
nml_doc .to_json_file ("%s.json" % nml_doc .id )
149
150
nml_doc .to_yaml_file ("%s.yaml" % nml_doc .id )
150
- nml_doc .to_bson_file ("%s.bson" % nml_doc .id )
151
- nml_doc .to_xml_file ("%s.xml" % nml_doc .id )
152
-
153
151
print (" >> Full document details in YAML format:\n " )
154
-
155
152
print (nml_doc .to_yaml ())
156
- print (nml_doc .to_xml ())
153
+
154
+ nml_doc .to_bson_file ("%s.bson" % nml_doc .id )
155
+
156
+ if sys .version_info >= (3 , 8 ):
157
+ nml_doc .to_xml_file ("%s.xml" % nml_doc .id )
158
+ print (" >> Full document details in XML format:\n " )
159
+ print (nml_doc .to_xml ())
157
160
158
161
print ("Generating documentation..." )
159
162
Original file line number Diff line number Diff line change @@ -119,6 +119,10 @@ def to_xml(self) -> str:
119
119
"""
120
120
Convert the data dictionary to an XML string representation using the ElementTree library.
121
121
"""
122
+ if sys .version_info < (3 , 8 ):
123
+ raise Exception (
124
+ "XML export functionality is not available in Python 3.7 or lower"
125
+ )
122
126
from modelspec .utils import build_xml_element
123
127
124
128
# root = ET.Element("modelspec")
You can’t perform that action at this time.
0 commit comments