Skip to content

Commit 25aa3bc

Browse files
Schema validation reuses existing ETree
1 parent 77d99d5 commit 25aa3bc

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

pretext/project/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def build(
685685
time_logger.log("XML syntax validated")
686686

687687
# Validate xml against schema; continue with warning if invalid:
688-
utils.xml_source_validates_against_schema(self.source_abspath())
688+
utils.xml_validates_against_schema(self.source_element())
689689
time_logger.log("source validated against schema")
690690

691691
# Clean output upon request

pretext/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,13 @@ def xml_syntax_is_valid(xmlfile: Path, root_tag: str = "pretext") -> bool:
204204
return True
205205

206206

207-
def xml_source_validates_against_schema(xmlfile: Path) -> bool:
207+
def xml_validates_against_schema(etree: ET) -> bool:
208208
# get path to RelaxNG schema file:
209209
schemarngfile = resources.resource_base_path() / "core" / "schema" / "pretext.rng"
210210

211211
# Open schemafile for validation:
212212
relaxng = ET.RelaxNG(file=schemarngfile)
213213

214-
# Parse xml file:
215-
source_xml = ET.parse(xmlfile)
216-
source_xml.xinclude()
217-
218214
# just for testing
219215
# ----------------
220216
# relaxng.validate(source_xml)
@@ -223,7 +219,7 @@ def xml_source_validates_against_schema(xmlfile: Path) -> bool:
223219

224220
# validate against schema
225221
try:
226-
relaxng.assertValid(source_xml)
222+
relaxng.assertValid(etree)
227223
log.info("PreTeXt source passed schema validation.")
228224
except ET.DocumentInvalid as err:
229225
log.debug(

0 commit comments

Comments
 (0)