XML Validator API Documentation¶
Overview¶
The XML Validator API validates XML content and returns a pretty-printed version of the XML.
It supports synchronous processing (direct body input) and asynchronous processing (remote file URL or uploaded file).
The API ensures that the XML is well-formed and provides formatted output with customizable indentation.
Base URL:
https://api.apidatatools.com/xml-validator-api
Endpoint (POST)¶
POST https://api.apidatatools.com/xml-validator-api
Headers¶
| Header | Description | Required | Example |
|---|---|---|---|
Content-Type | Must be application/json for body mode or application/octet-stream for binary uploads | Yes | application/json |
x-source-type | Defines input mode: body, url, or file | Optional (defaults to body) | body |
x-api-key | Your API key for authentication | Yes | abcd1234xyz |
Accepted File Extensions¶
This tool accepts the following file extensions for validation and formatting:
txt, xml, log
Input Example (Body Mode)¶
<root>
<child>value</child>
</root>"
Input Example (URL Mode)¶
{
"url": "https://example.com/sample.xml"
}
Input Example (File Mode)¶
{
"file": "user_uploads/abc123/sample.xml"
}
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/xml-validator-api" \
-H "Content-Type: application/xml" \
-H "x-source-type: body" \
-H "x-api-key: YOUR_API_KEY" \
-d '<root><child>value</child></root>'
Asynchronous (Remote File URL)¶
curl -X POST "https://api.apidatatools.com/xml-validator-api" \
-H "Content-Type: application/json" \
-H "x-source-type: url" \
-H "x-api-key: YOUR_API_KEY" \
-d '{"url": "https://example.com/sample.xml"}'
Asynchronous (Input File)¶
curl -X POST "https://api.apidatatools.com/xml-validator-api" \
-H "Content-Type: application/json" \
-H "x-source-type: file" \
-H "x-api-key: YOUR_API_KEY" \
-d '{"file": "user_uploads/abc123/sample.xml"}'
Example Response¶
Successful (Body Mode)¶
{
"status": "success",
"request_id": "b7e2f9a1-1234-4cde-9a56-7890abcd1234",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.xml",
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n <child>value</child>\n</root>\n"
}
Async Job Accepted¶
{
"status": "accepted",
"job_id": "job-1234abcd-5678efgh",
"status_url": "https://api.apidatatools.com/jobs/job-1234abcd-5678efgh",
"request_id": "b7e2f9a1-1234-4cde-9a56-7890abcd1234"
}
Error Handling¶
| Error Code | HTTP Status | Description | Example |
|---|---|---|---|
INVALID_XML | 400 | XML is malformed or invalid | {"status":"error","error":"INVALID_XML","details":{"message":"XML validation failed.","line":2,"column":5}} |
INVALID_BODY | 400 | Body is not valid JSON | {"status":"error","error":"INVALID_BODY","details":{"message":"Body must be valid JSON."}} |
INVALID_URL | 400 | URL is missing or invalid | {"status":"error","error":"INVALID_URL","details":{"message":"Missing or invalid 'url'."}} |
URL_UNREACHABLE | 400 | Remote URL cannot be reached | {"status":"error","error":"URL_UNREACHABLE","details":{"message":"Could not reach URL"}} |
URL_NOT_OK | 400 | Remote URL returned non-200 status | {"status":"error","error":"URL_NOT_OK","details":{"message":"URL returned HTTP 404, expected 200."}} |
FILE_TOO_LARGE | 413 | File exceeds plan limit | {"status":"error","error":"FILE_TOO_LARGE","details":{"message":"Remote file exceeds plan limit."}} |
INVALID_FILE_EXTENSION | 400 | File extension not supported | {"status":"error","error":"INVALID_FILE_EXTENSION","details":{"message":"Invalid or unsupported file extension"}} |
INVALID_SOURCE_TYPE | 400 | Invalid x-source-type header | {"status":"error","error":"INVALID_SOURCE_TYPE","details":{"message":"Must be 'url' or 'file'."}} |
INTERNAL_ERROR | 500 | Unexpected server error | {"status":"error","error":"INTERNAL_ERROR","details":{"message":"Failed to process your request"}} |
Async Job Status¶
To check the status of an asynchronous job, use the Status API:
GET https://api.apidatatools.com/jobs/{job_id}
Example Status Response for Async¶
{
"job_id": "job-1234abcd-5678efgh",
"status": "success",
"created_at": 1712345678,
"updated_at": 1712345689,
"result": {
"status": "success",
"file": "https://downloads.apidatatools.com/apidatatools_convert_abcdef1234567890.xml",
"request_id": "b7e2f9a1-1234-4cde-9a56-7890abcd1234",
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>\n <child>value</child>\n</root>\n"
}
}
If the job is still processing:
{
"job_id": "job-1234abcd-5678efgh",
"status": "queued",
"message": "Your job is being processed.",
"retry_after": 2
}
If the job failed:
{
"job_id": "job-1234abcd-5678efgh",
"status": "failed",
"error": {
"code": "INVALID_XML",
"message": "XML validation failed.",
"details": {"line": 2, "column": 5}
}
}
Notes for Developers¶
- The API supports three input modes:
body,url, andfile. - When
x-source-typeisurlorfile, the request is processed asynchronously, returning ajob_idandstatus_url. - Use the Status API to poll job results until completion.
- The
x-tab-spaceheader controls indentation for pretty-printing. Default is2. - The response always includes a
request_idfor traceability. - Output files are stored securely and accessible via a temporary URL.
- The preview field in the response contains the first 100 KB of formatted XML for quick inspection.