XML Schema (XSD) Validator API
Validate XML against an XML Schema (XSD 1.0, libxml2): errors with line, XPath and message; multi-file schemas with xs:include / xs:import in a ZIP.
Send the XML and its schema and get every validation error with line, col, xpath and the libxml2 message, plus a bilingual summary. The stage tells where it failed: xsd_parse (the schema is not well-formed), xsd_compile (the schema itself is wrong, e.g. an unknown type or a missing include), xml_parse (the document is not well-formed) or validate.
Schemas split over several files (xs:include, xs:import, e.g. UBL 2.1, ISO 20022, Vietnamese e-invoice and tax XSD packages) are supported: upload them as a ZIP in schema_zip and name the entry point with schema_main, or pass schemas as a { "file.xsd": "<xs:schema…>" } object. Files are resolved by their name or path inside the ZIP; nothing is fetched from the network.
Engine: libxml2 (MIT) compiled to WebAssembly, running in a separate APIBox Worker. XML Schema 1.0 only (no XSD 1.1 assertions); Schematron rules are not evaluated. External entities are never loaded. XML and schema up to 10 MB each (less on the free plan).
Markdown · OpenAPI · Postman · llms.txt
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
xml | body | string | yes | The XML document (or a multipart xml / file upload, xml_base64, xml_url). | |
xsd | body | string | no | The schema (text, multipart xsd, xsd_base64 or xsd_url). | |
schema_zip | body | file | no | ZIP with several .xsd files (multipart, schema_zip_base64 or schema_zip_url). | |
schema_main | body | string | no | Name of the main schema inside the ZIP. | |
schemas | body | object | no | Extra schema files { "name.xsd": "<xs:schema…>" } for includes / imports. |
Example
curl -X POST "https://apibox.io.vn/v1/xsd-validate" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"xml":"<invoice><no>A1</no><total>100</total></invoice>","xsd":"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:element name=\"invoice\"><xs:complexType><xs:sequence><xs:element name=\"no\" type=\"xs:int\"/><xs:element name=\"total\" type=\"xs:decimal\"/></xs:sequence></xs:complexType></xs:element></xs:schema>"}'const res = await fetch('https://apibox.io.vn/v1/xsd-validate', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"xml": "<invoice><no>A1</no><total>100</total></invoice>",
"xsd": "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:element name=\"invoice\"><xs:complexType><xs:sequence><xs:element name=\"no\" type=\"xs:int\"/><xs:element name=\"total\" type=\"xs:decimal\"/></xs:sequence></xs:complexType></xs:element></xs:schema>"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/xsd-validate",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"xml": "<invoice><no>A1</no><total>100</total></invoice>", "xsd": "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"><xs:element name=\"invoice\"><xs:complexType><xs:sequence><xs:element name=\"no\" type=\"xs:int\"/><xs:element name=\"total\" type=\"xs:decimal\"/></xs:sequence></xs:complexType></xs:element></xs:schema>"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/xsd-validate');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"xml":"<invoice><no>A1</no><total>100</total></invoice>","xsd":"<xs:schema xmlns:xs=\\"http://www.w3.org/2001/XMLSchema\\"><xs:element name=\\"invoice\\"><xs:complexType><xs:sequence><xs:element name=\\"no\\" type=\\"xs:int\\"/><xs:element name=\\"total\\" type=\\"xs:decimal\\"/></xs:sequence></xs:complexType></xs:element></xs:schema>"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"valid": false,
"stage": "validate",
"summary": "1 problem(s) at stage validate",
"summary_vi": "XML không khớp XSD (1 lỗi)",
"error_count": 1,
"errors": [
{
"line": 1,
"col": 0,
"level": "error",
"message": "Element 'no': 'A1' is not a valid value of the atomic type 'xs:int'.",
"xpath": "/invoice/no",
"file": "document.xml"
}
],
"schema_files": 1,
"ms": 57,
"engine": "libxml2 (XML Schema 1.0)"
}
Use cases
- Check e-invoice, tax or bank XML before sending it to the authority
- Validate UBL / ISO 20022 / SEPA files in an n8n or Make scenario
- Give users precise error lines when importing XML into your app
- Test schema changes against sample documents in CI
FAQ
Which XSD version is supported?
XML Schema 1.0 (libxml2). XSD 1.1 features such as xs:assert are refused with a clear error.
My schema imports other files. What do I send?
A ZIP with all .xsd files in schema_zip and the main file name in schema_main; includes are resolved by name or relative path.
Is there a built-in schema library?
Not yet: send the schema you were given. Official schemas change often and their licences differ, so APIBox does not redistribute them.
Related APIs
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
{ }JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.