Kiểm tra XML theo XSD online
Kiểm tra XML theo XML Schema (XSD 1.0, libxml2): lỗi kèm dòng, XPath và thông báo; hỗ trợ bộ XSD nhiều file (xs:include / xs:import) trong ZIP.
Kết quả
Bấm “Chạy” để xem kết quả.
Gửi XML và schema, nhận mọi lỗi kiểm tra kèm line, col, xpath và thông báo của libxml2, cùng phần tóm tắt song ngữ. Trường stage cho biết lỗi ở bước nào: xsd_parse (schema không đúng cú pháp XML), xsd_compile (bản thân schema sai, ví dụ kiểu dữ liệu không tồn tại hoặc thiếu file include), xml_parse (tài liệu không đúng cú pháp) hoặc validate.
Hỗ trợ schema chia thành nhiều file (xs:include, xs:import, ví dụ UBL 2.1, ISO 20022, bộ XSD hoá đơn điện tử và tờ khai thuế): tải lên dạng ZIP qua schema_zip và chỉ file chính bằng schema_main, hoặc gửi schemas dạng { "file.xsd": "<xs:schema…>" }. File được tìm theo tên hoặc đường dẫn trong ZIP; không tải gì từ mạng.
Bộ máy: libxml2 (MIT) biên dịch sang WebAssembly, chạy trong một Worker riêng của APIBox. Chỉ hỗ trợ XML Schema 1.0 (không có assertion của XSD 1.1); không chạy luật Schematron. Không bao giờ tải external entity. XML và schema tối đa 10 MB mỗi loại (gói Free thấp hơn).
Dùng trong code của bạn
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));Tài liệu API → Nhận API key miễn phí
Hỏi đáp
Hỗ trợ XSD phiên bản nào?
XML Schema 1.0 (libxml2). Tính năng của XSD 1.1 như xs:assert bị từ chối kèm thông báo rõ ràng.
Schema của tôi import file khác thì gửi thế nào?
Nén mọi file .xsd vào ZIP, gửi qua schema_zip và ghi tên file chính vào schema_main; include được tìm theo tên hoặc đường dẫn tương đối.
Có sẵn kho XSD không?
Chưa: hãy gửi schema bạn nhận được. XSD chính thức thay đổi thường xuyên và giấy phép mỗi nơi khác nhau nên APIBox không phân phối lại.