<div dir="ltr"><div dir="ltr">I did a bit more reading, and apparently, xsd-schema-validator uses Java under the hood! That won't do. Good for server-side or app maybe!</div><div dir="ltr"><br></div><div>Anyway, I think I'll keep the validator around in so people who complain that the component and meta statements must be in a certain order have some backbone for them.</div><div><br></div><div>Will do some more hunting. This validator seemed a bit out of date anyway.</div><div><br></div><div>John</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jun 23, 2024 at 4:40 AM John Carlson <<a href="mailto:yottzumm@gmail.com">yottzumm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">So I thought to myself. I've already written one X3D XML Schema JSON validator in Java. How about one in JavaScript?<div><br></div><div>So using online resources, I searched for a schema validator and found one, xsd-schema-validator. Within a matter of moments, I was able to hobble together a simple validator using your and my friend X3DJSONLD.js and now I can validate X3D JSON documents with XML schema (again!). Next, we'll work on a web-based one. Would X3DOM or X_ITE be able to follow my lead? Is there more actual good reasons why we can't adopt a JSON standard encoding for X3D?</div><div><br></div><div><br></div><div><div>let fs = require("fs");</div><div>let validator = require('xsd-schema-validator');</div><div>let X3DJSONLD = require('./X3DJSONLD.js');</div><div>let xmldom = require('@xmldom/xmldom');</div><div>let DOMImplementation = new xmldom.DOMImplementation();</div><div><br></div><div>function validateWithXMLSchema(jsobj, path) {</div><div> try {</div><div> [ child, xml ] = X3DJSONLD.loadJsonIntoDom(DOMImplementation, jsobj, path);</div><div> if (!xml) {</div><div> xml = X3DJSONLD.serializeDOM(jsobj, child, true);</div><div> }</div><div> const result = validator.validateXML(xml, '../../specifications/x3d-4.0.xsd');</div><div><br></div><div> return result;</div><div> } catch (err) {</div><div> console.error('validation error', err);</div><div> }</div><div>}</div><div><br></div><div>let promise = validateWithXMLSchema(JSON.parse(fs.readFileSync(process.argv[2]), process.argv[2]));</div><div>promise.then(</div><div> function (result) { console.log(result); },</div><div> function (rest) { console.error(rest); }</div><div>);</div></div><div>=======================================================</div><div>Example:</div><div><br></div><div><div>$ node xmlvalidate.js ../data/ball.json</div><div>Error: invalid xml (status=WITH_ERRORS)</div><div> [error] cvc-complex-type.2.4.a: Invalid content was found starting with element 'component'. One of '{meta}' is</div><div>expected. (8:50)</div><div> at buildError (C:\Users\john\X3DJSONLD\node_modules\xsd-schema-validator\lib\validator.js:195:16)</div><div> at finish (C:\Users\john\X3DJSONLD\node_modules\xsd-schema-validator\lib\validator.js:155:38)</div><div> at ChildProcess.<anonymous> (C:\Users\john\X3DJSONLD\node_modules\xsd-schema-validator\lib\validator.js:205:9)</div><div> at ChildProcess.emit (node:events:519:28)</div><div> at ChildProcess._handle.onexit (node:internal/child_process:294:12) {</div><div> valid: false,</div><div> result: 'WITH_ERRORS',</div><div> messages: [</div><div> "[error] cvc-complex-type.2.4.a: Invalid content was found starting with element 'component'. One of '{meta}' is exp</div><div>ected. (8:50)"</div><div> ]</div><div>}</div></div><div>=====================================</div><div>Another:</div><div>$ node xmlvalidate.js ../data/abox.json</div><div>{ valid: true, result: 'OK', messages: [] }</div></div></div></div></div>
</blockquote></div>