XML Validation API v1.0
Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.
Please note this API is only available if the current active Halo license contains the XML Validation entitlement
Authentication
-
HTTP Authentication, scheme: Basic
-
HTTP Authentication, scheme: Bearer
Validate XML
API endpoints to validate XML documents against their schema definitions and/or predefined scanning rules
Parses and validates an XML string against a provided schema and/or predefined set of rules
Code samples
# You can also use wget
curl -X POST /api/v1/validate-xml \
-H 'Content-Type: multipart/form-data' \
-H 'Accept: application/json' \
-H 'X-Session-Id: string'
POST /api/v1/validate-xml HTTP/1.1
Content-Type: multipart/form-data
Accept: application/json
X-Session-Id: string
const inputBody = '{
"file": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<example>\n <field>Value</field>\n</example>",
"schema": "<xs:schema attributeFormDefault=\"unqualified\" elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n <xs:element name=\"example\">\n <xs:complexType>\n <xs:sequence>\n <xs:element name=\"field\" type=\"xs:string\" />\n </xs:sequence>\n </xs:complexType>\n </xs:element>\n</xs:schema>"
}';
const headers = {
'Content-Type':'multipart/form-data',
'Accept':'application/json',
'X-Session-Id':'string'
};
fetch('/api/v1/validate-xml',
{
method: 'POST',
body: inputBody,
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
require 'rest-client'
require 'json'
headers = {
'Content-Type' => 'multipart/form-data',
'Accept' => 'application/json',
'X-Session-Id' => 'string'
}
result = RestClient.post '/api/v1/validate-xml',
params: {
}, headers: headers
p JSON.parse(result)
import requests
headers = {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json',
'X-Session-Id': 'string'
}
r = requests.post('/api/v1/validate-xml', headers = headers)
print(r.json())
<?php
require 'vendor/autoload.php';
$headers = array(
'Content-Type' => 'multipart/form-data',
'Accept' => 'application/json',
'X-Session-Id' => 'string',
);
$client = new \GuzzleHttp\Client();
// Define array of request body.
$request_body = array();
try {
$response = $client->request('POST','/api/v1/validate-xml', array(
'headers' => $headers,
'json' => $request_body,
)
);
print_r($response->getBody()->getContents());
}
catch (\GuzzleHttp\Exception\BadResponseException $e) {
// handle exception or api errors.
print_r($e->getMessage());
}
// ...
URL obj = new URL("/api/v1/validate-xml");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
package main
import (
"bytes"
"net/http"
)
func main() {
headers := map[string][]string{
"Content-Type": []string{"multipart/form-data"},
"Accept": []string{"application/json"},
"X-Session-Id": []string{"string"},
}
data := bytes.NewBuffer([]byte{jsonReq})
req, err := http.NewRequest("POST", "/api/v1/validate-xml", data)
req.Header = headers
client := &http.Client{}
resp, err := client.Do(req)
// ...
}
POST /api/v1/validate-xml
This endpoint accepts requests to validate an XML document against a provided XML schema definition. Alternatively or in addition to, the endpoint can scan the provided XML document against Glasswall’s set of predefined rules.’
Body parameter
file: |-
<?xml version="1.0" encoding="UTF-8"?>
<example>
<field>Value</field>
</example>
schema: >-
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="example">
<xs:complexType>
<xs:sequence>
<xs:element name="field" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Parameters
Name | In | Type | Required | Description |
---|---|---|---|---|
X-Session-Id | header | string | false | A string that can be used to group requests in reports |
body | body | object | false | none |
» file | body | object | true | This field contains the XML document to be validated. |
» schema | body | object | true | Required if Validate is set to ‘true’. This field contains the XML Schema definition to validate the document against. |
Example responses
Error returned if the XML document failed validation against the schema, or fails check against a list of predefined rules.
{
"ValidationResults": [
"The prefix 'xs' for element 'xs:schema' is not bound."
]
}
400 Error returned if the XML document was malformed and could not be parsed
{
"Errors": [
{
"ErrorCode": 4101,
"ErrorDescription": "Failed to parse XML"
}
]
}
400 Error returned if the XML schema definition was malformed and could not be parsed
{
"Errors": [
{
"ErrorCode": 4102,
"ErrorDescription": "The Schema field is required when Validate is True."
}
]
}
400 Error returned if both flags ‘scan’ and ‘validate’ are set to false
{
"Errors": [
{
"ErrorCode": 4001,
"ErrorDescription": "Unable to process due to both scanning and validation being disabled."
}
]
}
The current active license has expired, or the system cannot find an active license. Upload an active license via the License Management Service and try again.
{
"Errors": [
{
"ErrorCode": 5012,
"ErrorDescription": "No license was set."
}
]
}
The current active license was missing a required entitlement. Upload a new license via the License Management Service and try again.
{
"Errors": [
{
"ErrorCode": 5013,
"ErrorDescription": "The XML Validation license entitlement was missing"
}
]
}
The system cannot accept new requests as it is currently at max load. Inspect the “Retry-After” header for a time to wait before retrying
{
"Errors": [
{
"ErrorCode": 4029,
"ErrorDescription": "Too many requests"
}
]
}
Responses
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | OK | None |
400 | Bad Request | Bad Request | ErrorResponse |
401 | Unauthorized | Unauthorized | None |
403 | Forbidden | Forbidden | ErrorResponse |
429 | Too Many Requests | Too Many Requests | ErrorResponse |
500 | Internal Server Error | Internal Server Error | None |
Response Schema
Schemas
Error
{
"errorCode": 0,
"errorDescription": "string"
}
Properties
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
errorCode | integer(int32)¦null | false | none | The Glasswall engine error code |
errorDescription | string¦null | false | none | none |
ErrorResponse
{
"errors": [
{
"errorCode": 0,
"errorDescription": "string"
}
]
}
Properties
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
errors | [Error]¦null | false | none | The error text relating to the particular error |