diff --git a/libraries/bxdf/genglsl/gltf_pbr.mtlx b/libraries/bxdf/genglsl/gltf_pbr.mtlx
index 73504326bc..c60c566b0b 100644
--- a/libraries/bxdf/genglsl/gltf_pbr.mtlx
+++ b/libraries/bxdf/genglsl/gltf_pbr.mtlx
@@ -308,7 +308,7 @@
-
+
diff --git a/libraries/bxdf/genglsl/open_pbr_surface.mtlx b/libraries/bxdf/genglsl/open_pbr_surface.mtlx
index c57d30fe1a..85d8717d4e 100644
--- a/libraries/bxdf/genglsl/open_pbr_surface.mtlx
+++ b/libraries/bxdf/genglsl/open_pbr_surface.mtlx
@@ -211,21 +211,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -546,8 +546,7 @@
-
+
diff --git a/libraries/bxdf/genmdl/open_pbr_surface.mtlx b/libraries/bxdf/genmdl/open_pbr_surface.mtlx
index bbdb1cc9bc..d040812085 100644
--- a/libraries/bxdf/genmdl/open_pbr_surface.mtlx
+++ b/libraries/bxdf/genmdl/open_pbr_surface.mtlx
@@ -210,21 +210,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -326,7 +326,7 @@
-
+
@@ -543,8 +543,7 @@
-
+
diff --git a/libraries/bxdf/gltf_pbr.mtlx b/libraries/bxdf/gltf_pbr.mtlx
index 821506394c..3675bae4c6 100644
--- a/libraries/bxdf/gltf_pbr.mtlx
+++ b/libraries/bxdf/gltf_pbr.mtlx
@@ -353,7 +353,7 @@
-
+
diff --git a/libraries/bxdf/lama/lama_iridescence.mtlx b/libraries/bxdf/lama/lama_iridescence.mtlx
index 7728f96d10..5383f5f2ab 100644
--- a/libraries/bxdf/lama/lama_iridescence.mtlx
+++ b/libraries/bxdf/lama/lama_iridescence.mtlx
@@ -72,7 +72,7 @@
- />
+
diff --git a/libraries/bxdf/open_pbr_surface.mtlx b/libraries/bxdf/open_pbr_surface.mtlx
index 87084bf7fe..2728d470df 100644
--- a/libraries/bxdf/open_pbr_surface.mtlx
+++ b/libraries/bxdf/open_pbr_surface.mtlx
@@ -301,21 +301,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libraries/bxdf/translation/open_pbr_to_standard_surface.mtlx b/libraries/bxdf/translation/open_pbr_to_standard_surface.mtlx
index ec7bb19a98..f9ca1cd446 100644
--- a/libraries/bxdf/translation/open_pbr_to_standard_surface.mtlx
+++ b/libraries/bxdf/translation/open_pbr_to_standard_surface.mtlx
@@ -53,7 +53,7 @@
-
+
diff --git a/libraries/bxdf/translation/standard_surface_to_open_pbr.mtlx b/libraries/bxdf/translation/standard_surface_to_open_pbr.mtlx
index 535f65b700..4edc743966 100644
--- a/libraries/bxdf/translation/standard_surface_to_open_pbr.mtlx
+++ b/libraries/bxdf/translation/standard_surface_to_open_pbr.mtlx
@@ -14,12 +14,12 @@
-
+
-
+
@@ -36,7 +36,7 @@
-
+
@@ -64,7 +64,7 @@
-
+
@@ -132,7 +132,7 @@
-
+
@@ -271,7 +271,7 @@
-
+
diff --git a/libraries/bxdf/usd_preview_surface.mtlx b/libraries/bxdf/usd_preview_surface.mtlx
index 23a01462a7..657921ee9b 100644
--- a/libraries/bxdf/usd_preview_surface.mtlx
+++ b/libraries/bxdf/usd_preview_surface.mtlx
@@ -64,12 +64,12 @@
-
+
-
+
diff --git a/libraries/cmlib/cmlib_ng.mtlx b/libraries/cmlib/cmlib_ng.mtlx
index 7271bd944b..4f37d0a5dd 100644
--- a/libraries/cmlib/cmlib_ng.mtlx
+++ b/libraries/cmlib/cmlib_ng.mtlx
@@ -315,8 +315,7 @@
-
+
@@ -355,8 +354,7 @@
-
+
diff --git a/libraries/pbrlib/pbrlib_defs.mtlx b/libraries/pbrlib/pbrlib_defs.mtlx
index 0bb75716e6..039d78bdd6 100644
--- a/libraries/pbrlib/pbrlib_defs.mtlx
+++ b/libraries/pbrlib/pbrlib_defs.mtlx
@@ -430,8 +430,8 @@
-
-
+
+
diff --git a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
index 7bfbc3906b..2b281193ca 100644
--- a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
+++ b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
@@ -732,9 +732,9 @@
-
-
-
+
+
+
diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
index 28e2b35465..24e0587aa3 100644
--- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
+++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
@@ -266,8 +266,10 @@
-
-
+
+
+
+
@@ -744,9 +746,9 @@
-
-
-
+
+
+
diff --git a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
index 81da6169ae..c0b647dca9 100644
--- a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
+++ b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
@@ -722,9 +722,9 @@
-
-
-
+
+
+
diff --git a/libraries/stdlib/stdlib_defs.mtlx b/libraries/stdlib/stdlib_defs.mtlx
index 499b91d890..058f93da96 100644
--- a/libraries/stdlib/stdlib_defs.mtlx
+++ b/libraries/stdlib/stdlib_defs.mtlx
@@ -303,7 +303,7 @@
-
+
-
+
+
@@ -4970,7 +4971,7 @@
-->
-
+
@@ -5015,7 +5016,7 @@
-->
-
+
diff --git a/libraries/stdlib/stdlib_ng.mtlx b/libraries/stdlib/stdlib_ng.mtlx
index 08025aedd2..0e4907a012 100644
--- a/libraries/stdlib/stdlib_ng.mtlx
+++ b/libraries/stdlib/stdlib_ng.mtlx
@@ -1201,7 +1201,7 @@
-
+
@@ -1212,7 +1212,7 @@
-
+
@@ -3285,26 +3285,26 @@
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
@@ -3317,264 +3317,264 @@
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
+
-
+
-
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
+
+
-
+
-
+
-
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
-
+
-
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
+
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
+
-
+
-
+
@@ -6375,8 +6375,8 @@
-
-
+
+
@@ -6386,37 +6386,37 @@
-->
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/python/Scripts/mxformat.py b/python/Scripts/mxformat.py
index 0b327883bd..010d32e3a6 100644
--- a/python/Scripts/mxformat.py
+++ b/python/Scripts/mxformat.py
@@ -6,21 +6,31 @@
import argparse
import os
+import xml.etree.ElementTree as ET
import MaterialX as mx
+def is_well_formed(xml_string):
+ error = ''
+ try:
+ ET.fromstring(xml_string)
+ except ET.ParseError as e:
+ error = str(e)
+
def main():
parser = argparse.ArgumentParser(description="Reformat a folder of MaterialX documents in place.")
- parser.add_argument("--yes", dest="yes", action="store_true", help="Proceed without asking for confirmation from the user.")
- parser.add_argument('--upgrade', dest='upgrade', action="store_true", help='Upgrade documents to the latest version of the standard.')
+ parser.add_argument('-y', '--yes', dest='yes', action="store_true", help="Proceed without asking for confirmation from the user.")
+ parser.add_argument('-u', '--upgrade', dest='upgrade', action="store_true", help='Upgrade documents to the latest version of the standard.')
+ parser.add_argument('-v', '--validate', dest='validate', action="store_true", help='Perform MaterialX validation on documents after reformatting.')
+ parser.add_argument('-x', '--xml_syntax', dest='xml_syntax', action="store_true", help='Check XML syntax after reformatting.')
parser.add_argument(dest="inputFolder", help="An input folder to scan for MaterialX documents.")
opts = parser.parse_args()
validDocs = dict()
for root, dirs, files in os.walk(opts.inputFolder):
- for file in files:
- if file.endswith('.mtlx'):
- filename = os.path.join(root, file)
+ for filename in files:
+ fullpath = os.path.join(root, filename)
+ if fullpath.endswith('.mtlx'):
doc = mx.createDocument()
try:
readOptions = mx.XmlReadOptions()
@@ -28,11 +38,11 @@ def main():
readOptions.readNewlines = True
readOptions.upgradeVersion = opts.upgrade
try:
- mx.readFromXmlFile(doc, filename, mx.FileSearchPath(), readOptions)
+ mx.readFromXmlFile(doc, fullpath, mx.FileSearchPath(), readOptions)
except Exception as err:
- print('Skipping "' + file + '" due to exception: ' + str(err))
+ print('Skipping "' + filename + '" due to exception: ' + str(err))
continue
- validDocs[filename] = doc
+ validDocs[fullpath] = doc
except mx.Exception:
pass
@@ -53,7 +63,22 @@ def main():
if answer != 'y' and answer != 'Y':
return
+ validate = opts.validate
+ if validate:
+ print(f'- Validate documents')
+ xml_syntax = opts.xml_syntax
+ if xml_syntax:
+ print(f'- Check XML syntax')
for (filename, doc) in validDocs.items():
+ if xml_syntax:
+ xml_string = mx.writeToXmlString(doc)
+ errors = is_well_formed(xml_string)
+ if errors:
+ print(f'- Warning: Document {filename} is not well-formed XML: {errors}')
+ if validate:
+ is_valid, errors = doc.validate()
+ if not is_valid:
+ print(f'- Warning: Document {filename} is invalid. Errors {errors}.')
mx.writeToXmlFile(doc, filename)
if opts.upgrade:
diff --git a/resources/Materials/TestSuite/stdlib/conditional/conditional_logic.mtlx b/resources/Materials/TestSuite/stdlib/conditional/conditional_logic.mtlx
index d931b5bf6e..f9187b1d41 100644
--- a/resources/Materials/TestSuite/stdlib/conditional/conditional_logic.mtlx
+++ b/resources/Materials/TestSuite/stdlib/conditional/conditional_logic.mtlx
@@ -24,7 +24,7 @@
-
+