To validate XML file by the XSD. Able to nested XSD by xs:include, xs:redefine, and xs:import which have different namespace. Now it is able to run in web worker and better user experience. It has been tested in dev and build package. It also able to use
npm install xml-xsd-validator-browserxml-xsd-validator-browser v1.0.9
libxml2-wasm with support for recursive XSD imports/includes/redefines via a MapInputProvider.
, , and .
MapInputProvider to provide XSD files from memory (no network fetch needed during validation).
bash
npm i xml-xsd-validator-browser
`
🧰 Usage Example
`ts
import { useWorker, validateXml } from "xml-xsd-validator-browser";
function test1() {
const xmlText =
;
validateXml(xmlText)
.catch(err => {
console.log(err) // returning array contains object has name:"XMLValidateError"
})
}
test1()
async function test2() {
const xmlText =
;
const mainSchemaUrl = "https://ferdisap.github.io/schema/s1000d/S1000D_5-0/xml_schema_flat/appliccrossreftable.xsd";
const { validate, terminate } = useWorker()
validate(xmlText, mainSchemaUrl)
// never get resolved if the file is valid
.then(response => {
const { id, status, bags } = response;
console.log(id, status, bags) // returning array contains object has name:"XMLValidateError"
})
.catch(response => {
console.log(response)
terminate()
})
}
test2()
// expected of test1 and tes2
/**
[
{
name: "XMLValidateError",
type: "xsd",
detail: {
message: "Element 'identAndStatusSection': Missing child element(s). Expected is ( dmAddress ).\\n",
file: "",
line: 3,
col: 1
}
},
{
name: "XMLValidateError",
type: "xsd",
detail: {
message: "Element 'dmodule': Missing child element(s). Expected is ( content ).\\n",
file: "",
line: 2,
col: 1
}
}
]
*/
`
Local development
1. clone this repository.
2. run npm install && npm run vite:build:test
3. open the index.html`