π W3C Schema Governance, Hierarchical Contracts & Namespace Integrity
While modern web architectures rely heavily on JSON, mission-critical enterprise systemsβincluding banking gateways, healthcare transaction brokers, legacy SOAP web services, and telecommunications platformsβtransmit business payloads formatted as Extensible Markup Language (XML). In XML ecosystems, functional element assertions (such as evaluating an XPath text string) do not protect downstream consumers from breaking contract regressions, missing required attributes, invalid namespace prefixes, or out-of-order element sequences. XML Schema Definition (XSD) provides formal, grammar-level contract testing standardized by the W3C XML Schema Recommendation. Using REST Assured's native matcher integration via io.restassured.matcher.RestAssuredMatchers.matchesXsd() and matchesXsdInClasspath(), automation engineers validate entire XML response trees against strict XSD specifications in a single assertion line, enforcing element hierarchies, namespace bindings, attribute requirements, and XML schema type invariants with compile-time precision.
INBOUND XML WIRE RESPONSE TO XSD VALIDATION ENGINE PIPELINE:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WIRE RESPONSE STREAM (HTTP 200 OK | Content-Type: application/xml; charset=utf-8) β
β <?xml version="1.0" encoding="UTF-8"?> β
β <StudentEnrollmentRecord xmlns="https://schemas.nikita-infotech.com/academic/v1"> β
β <StudentId>STU-88219</StudentId> β
β <FullName>Nikita Sharma</FullName> β
β <EnrolledCredits>16</EnrolledCredits> β
β <Status>ACTIVE</Status> β
β </StudentEnrollmentRecord> β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ (Passed into .then().body(matchesXsdInClasspath(...)))
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β REST ASSURED XSD MATCHER ENGINE (io.restassured.matcher.RestAssuredMatchers) β
β βββ 1. Classpath Resolver: Loads "schemas/student-record.xsd" from target/test-classes β
β βββ 2. JAXP SchemaFactory: Instantiates javax.xml.validation.SchemaFactory (W3C XML Schema) β
β βββ 3. XML Parser Builder: Compiles XSD into in-memory javax.xml.validation.Schema object β
β βββ 4. Secure Processing: Applies FEATURE_SECURE_PROCESSING (Blocks XXE / billion laughs) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ (Evaluates Structural & Type Invariants)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β W3C XSD GRAMMAR CONFORMANCE VERIFICATION β
β βββ Namespace Binding βββΊ xmlns == targetNamespace ("https://schemas.nikita-infotech.com") β
β βββ Element Sequence βββΊ xs:sequence order strictly enforced: StudentId β FullName β ... β
β βββ Cardinality Rules βββΊ minOccurs="1", maxOccurs="1" on mandatory elements β
β βββ Data Type Casting βββΊ EnrolledCredits is xs:positiveInteger, Status matches xs:enumeration β
β βββ Attribute Validity βββΊ xs:attribute use="required", type="xs:ID" β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββ
βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββ
β XSD VALIDATION PASS β β XSD VALIDATION FAILURE β
ββββββββββββββββββββββββββββββββββββββββββββββββ€ ββββββββββββββββββββββββββββββββββββββββββββββββ€
β Pipeline continues seamlessly to downstream β β Throws SAXParseException via Hamcrest β
β XPath assertions or XML POJO unmarshalling β β Error output reports exact line, column, β
β [W3C CONTRACT COMPLIANCE CONFIRMED] β β missing tags, and schema violation details β
ββββββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββ
targetNamespace declarations, complexType structures, xs:sequence ordering, xs:restriction facets (regex patterns, enumerations, min/max bounds), and mandatory XML attributes.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://schemas.nikita-infotech.com/academic/v1"
xmlns:tns="https://schemas.nikita-infotech.com/academic/v1"
elementFormDefault="qualified">
<!-- ROOT ELEMENT DECLARATION -->
<xs:element name="StudentEnrollmentRecord">
<xs:complexType>
<xs:sequence>
<!-- Simple Element with Regex Restriction Pattern -->
<xs:element name="StudentId">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="STU-[0-9]{5}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- String Element with Length Facets -->
<xs:element name="FullName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="3"/>
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- Numeric Element with Min/Max Integer Boundaries -->
<xs:element name="EnrolledCredits">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- Decimal Element for Academic GPA -->
<xs:element name="Gpa">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0.00"/>
<xs:maxInclusive value="4.00"/>
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- Enumerated String Facet -->
<xs:element name="Status">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ENROLLED"/>
<xs:enumeration value="ACTIVE"/>
<xs:enumeration value="PROBATION"/>
<xs:enumeration value="GRADUATED"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<!-- Nested Complex Type Collection: List of Courses -->
<xs:element name="EnrolledCourses">
<xs:complexType>
<xs:sequence>
<xs:element name="Course" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="CourseCode" type="xs:string"/>
<xs:element name="Title" type="xs:string"/>
<xs:element name="Credits" type="xs:positiveInteger"/>
</xs:sequence>
<xs:attribute name="courseId" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<!-- Mandatory XML Attribute on Root Element -->
<xs:attribute name="academicYear" type="xs:positiveInteger" use="required"/>
<xs:attribute name="campusCode" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
matchesXsdInClasspath("schemas/student-record.xsd") in REST Assured to assert that the returned XML response strictly adheres to the XSD definition.
package com.nikita.restassured.xml;
import io.restassured.http.ContentType;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsdInClasspath;
import static org.hamcrest.Matchers.equalTo;
public class BasicXsdValidationTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Validate XML API response against W3C XSD schema located in test resources classpath")
public void testStudentRecordXsdInClasspath() {
given()
.baseUri(BASE_URI)
.accept(ContentType.XML)
.header("X-Tenant-Id", "MH-PUNE-01")
.pathParam("studentId", "STU-88219")
.log().ifValidationFails()
.when()
.get("/academic/xml/students/{studentId}")
.then()
.log().ifValidationFails()
// 1. Assert transport headers and status
.statusCode(200)
.contentType(ContentType.XML)
// 2. Validate entire XML tree against W3C XSD schema in classpath
.body(matchesXsdInClasspath("schemas/student-record.xsd"))
// 3. Layer specific business logic assertions on verified XML nodes
.body("StudentEnrollmentRecord.StudentId", equalTo("STU-88219"))
.body("StudentEnrollmentRecord.Status", equalTo("ACTIVE"));
System.out.println("[β] XML response successfully conformed to W3C XSD schema in classpath.");
}
}
java.io.File, java.io.InputStream, java.io.Reader, or raw inline XSD XML string directly into matchesXsd().
package com.nikita.restassured.xml;
import io.restassured.http.ContentType;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import static io.restassured.RestAssured.given;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsd;
public class DiverseXsdSourcesTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Validate XML against XSD loaded from java.io.File")
public void testValidateXsdFromFile() {
File xsdFile = new File("src/test/resources/schemas/student-record.xsd");
given()
.baseUri(BASE_URI)
.accept(ContentType.XML)
.pathParam("studentId", "STU-88219")
.when()
.get("/academic/xml/students/{studentId}")
.then()
.statusCode(200)
// Validating from explicit File handle:
.body(matchesXsd(xsdFile));
System.out.println("[β] XML validated successfully from java.io.File handle.");
}
@Test(description = "Validate XML against XSD loaded from an InputStream")
public void testValidateXsdFromInputStream() throws IOException {
try (InputStream stream = new FileInputStream("src/test/resources/schemas/student-record.xsd")) {
given()
.baseUri(BASE_URI)
.accept(ContentType.XML)
.pathParam("studentId", "STU-88219")
.when()
.get("/academic/xml/students/{studentId}")
.then()
.statusCode(200)
// Validating from an InputStream:
.body(matchesXsd(stream));
}
System.out.println("[β] XML validated successfully from java.io.InputStream.");
}
@Test(description = "Validate XML against inline XSD String using StringReader")
public void testValidateXsdFromInlineString() {
// Minimal inline W3C XSD asserting health status XML
String inlineXsd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <xs:element name=\"ServiceHealth\">\n" +
" <xs:complexType>\n" +
" <xs:sequence>\n" +
" <xs:element name=\"Status\" type=\"xs:string\"/>\n" +
" <xs:element name=\"Timestamp\" type=\"xs:dateTime\"/>\n" +
" </xs:sequence>\n" +
" </xs:complexType>\n" +
" </xs:element>\n" +
"</xs:schema>";
given()
.baseUri(BASE_URI)
.accept(ContentType.XML)
.when()
.get("/health/xml")
.then()
.statusCode(200)
// Validating from raw inline String:
.body(matchesXsd(new StringReader(inlineXsd)));
System.out.println("[β] XML validated successfully from inline XSD StringReader.");
}
}
xmlns), prefixed namespaces (xmlns:acad), and multi-namespace schemas across federated enterprise models.
package com.nikita.restassured.xml;
import io.restassured.http.ContentType;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsdInClasspath;
import static org.hamcrest.Matchers.equalTo;
public class XmlNamespaceValidationTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Validate multi-namespace XML payload containing qualified prefix elements")
public void testNamespaceQualifiedXmlValidation() {
// Target XML response contains explicit namespace prefixes:
// <acad:StudentEnrollment xmlns:acad="https://schemas.nikita-infotech.com/academic/v1"
// xmlns:sec="https://schemas.nikita-infotech.com/security/v1">
// <acad:StudentId>STU-88219</acad:StudentId>
// <sec:SecurityClearanceLevel>TIER_2</sec:SecurityClearanceLevel>
// </acad:StudentEnrollment>
given()
.baseUri(BASE_URI)
.accept(ContentType.XML)
.pathParam("studentId", "STU-88219")
.when()
.get("/academic/xml/namespaced-students/{studentId}")
.then()
.statusCode(200)
.contentType(ContentType.XML)
// matchesXsdInClasspath validates across imported namespace schemas via :
.body(matchesXsdInClasspath("schemas/namespaced-student-record.xsd"))
// Value assertions evaluating specific namespace-qualified nodes:
.body("StudentEnrollment.StudentId", equalTo("STU-88219"))
.body("StudentEnrollment.SecurityClearanceLevel", equalTo("TIER_2"));
System.out.println("[β] Multi-namespace XML response confirmed compliant with composite XSD.");
}
}
SchemaFactory to prevent Billion Laughs entity expansion attacks.
package com.nikita.restassured.xml;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.File;
import java.io.StringReader;
import static io.restassured.RestAssured.given;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsdInClasspath;
public class XxeSecurityDefenseTest {
@Test(description = "Verify REST Assured XSD validation disallows malicious external DTD entities (XXE Defense)")
public void testSecureXsdProcessing() throws Exception {
// Construct a safe, hardened W3C SchemaFactory explicitly
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// 1. Enforce W3C secure processing feature
schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
// 2. Disallow external DTDs completely to block XXE file exfiltration attacks
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
// 3. Disallow external schema redirection over insecure protocols
schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file,http,https");
// Compile schema with security features engaged
File schemaFile = new File("src/test/resources/schemas/student-record.xsd");
Schema safeSchema = schemaFactory.newSchema(schemaFile);
Validator validator = safeSchema.newValidator();
// Malicious XML containing XXE entity pointing to local /etc/passwd or sensitive files:
String maliciousXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE StudentEnrollmentRecord [\n" +
" <!ENTITY xxe SYSTEM \"file:///etc/passwd\">\n" +
"]>\n" +
"<StudentEnrollmentRecord xmlns=\"https://schemas.nikita-infotech.com/academic/v1\" academicYear=\"2026\">\n" +
" <StudentId>STU-88219</StudentId>\n" +
" <FullName>&xxe;</FullName>\n" +
" <EnrolledCredits>16</EnrolledCredits>\n" +
" <Gpa>3.85</Gpa>\n" +
" <Status>ACTIVE</Status>\n" +
"</StudentEnrollmentRecord>";
try {
// Validator rejects external entity reference due to ACCESS_EXTERNAL_DTD policy:
validator.validate(new StreamSource(new StringReader(maliciousXml)));
Assert.fail("SECURITY VULNERABILITY: Validator failed to block malicious external entity!");
} catch (SAXException e) {
System.out.println("[β] SECURE: Parser successfully blocked XXE payload: " + e.getMessage());
Assert.assertTrue(e.getMessage().contains("external") || e.getMessage().contains("DOCTYPE"));
}
}
@Test(description = "Verify REST Assured native matchesXsdInClasspath enforces secure processing by default")
public void testNativeRestAssuredSecurity() {
given()
.baseUri("https://staging-api.nikita-infotech.com/v1")
.accept("application/xml")
.pathParam("studentId", "STU-88219")
.when()
.get("/academic/xml/students/{studentId}")
.then()
.statusCode(200)
.body(matchesXsdInClasspath("schemas/student-record.xsd"));
System.out.println("[β] Native REST Assured XSD validator executed securely.");
}
}
matchesXsdInClasspath() into a ResponseSpecBuilder template so that all inheriting tests automatically verify status codes, XML content types, latency, and XSD grammar.
package com.nikita.restassured.xml;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.ResponseSpecification;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsdInClasspath;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
public class XsdResponseSpecTest {
private ResponseSpecification xmlContractResponseSpec;
@BeforeClass
public void setupXmlContractSpecification() {
// Standardize 200 OK + XML ContentType + Latency SLA + W3C XSD in a single shared spec
xmlContractResponseSpec = new ResponseSpecBuilder()
.expectStatusCode(200)
.expectContentType(ContentType.XML)
.expectResponseTime(lessThan(1500L)) // 1.5s SLA ceiling
// Embed XSD schema matcher directly into the specification template:
.expectBody(matchesXsdInClasspath("schemas/student-record.xsd"))
.build();
System.out.println("[*] Compiled XML Contract ResponseSpecification template with embedded XSD.");
}
@Test(description = "Verify XML endpoint inheriting XSD contract validation from shared specification")
public void testStudentRecordInheritingXsdSpec() {
given()
.baseUri("https://staging-api.nikita-infotech.com/v1")
.accept(ContentType.XML)
.pathParam("studentId", "STU-88219")
.when()
.get("/academic/xml/students/{studentId}")
.then()
// In one call: validates status 200, Content-Type: application/xml, SLA < 1.5s, and W3C XSD!
.spec(xmlContractResponseSpec)
// Layer specific functional node assertions:
.body("StudentEnrollmentRecord.StudentId", equalTo("STU-88219"))
.body("StudentEnrollmentRecord.EnrolledCredits", equalTo("16"));
System.out.println("[β] Verified endpoint against centralized XML contract specification.");
}
}
package com.nikita.restassured.xml;
import io.restassured.http.ContentType;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsdInClasspath;
import static org.hamcrest.Matchers.*;
public class HybridXsdAndXPathTest {
private static final String BASE_URI = "https://staging-api.nikita-infotech.com/v1";
@Test(description = "Perform hybrid validation: W3C XSD grammar compliance + deep XPath evaluation")
public void testHybridXsdAndXPathAssertions() {
given()
.baseUri(BASE_URI)
.accept(ContentType.XML)
.pathParam("studentId", "STU-88219")
.when()
.get("/academic/xml/students/{studentId}")
.then()
.statusCode(200)
.contentType(ContentType.XML)
// 1. Contract Phase: Ensure entire XML document adheres to W3C XSD
.body(matchesXsdInClasspath("schemas/student-record.xsd"))
// 2. Functional Phase: XPath assertions targeting attributes and collections
.body("StudentEnrollmentRecord.@academicYear", equalTo("2026"))
// XPath: Select title of course having code 'REST-JAVA-201'
.body("StudentEnrollmentRecord.EnrolledCourses.Course.find { it.CourseCode == 'REST-JAVA-201' }.Title",
equalTo("REST Assured Masterclass"))
// XPath Collection Count: Verify at least 1 course is returned
.body("StudentEnrollmentRecord.EnrolledCourses.Course.size()", greaterThanOrEqualTo(1))
// XPath Attribute Extraction: Check XML attribute on first course element
.body("StudentEnrollmentRecord.EnrolledCourses.Course[0].@courseId", startsWith("CRS-"));
System.out.println("[β] Hybrid contract (XSD) and functional (XPath) assertions passed.");
}
}
package com.nikita.restassured.xml;
import org.testng.annotations.Test;
import java.io.StringReader;
import static io.restassured.matcher.RestAssuredMatchers.matchesXsd;
public class XsdViolationTriageTest {
// ==========================================================================
// SIMULATING COMMON XSD SCHEMA VIOLATIONS:
// 1. SEQUENCE ORDER VIOLATION: <FullName> sent BEFORE <StudentId> in <xs:sequence>
// 2. MISSING MANDATORY ATTRIBUTE: <StudentEnrollmentRecord> lacks academicYear
// 3. REGEX PATTERN MISMATCH: StudentId is "INVALID_ID" (Must match STU-[0-9]{5})
// ==========================================================================
@Test(description = "Demonstrate detailed diagnostic failure output produced by SAX parser on XSD mismatch")
public void testDiagnoseXsdSchemaViolations() {
String xsdGrammar = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <xs:element name=\"StudentRecord\">\n" +
" <xs:complexType>\n" +
" <xs:sequence>\n" +
" <xs:element name=\"StudentId\">\n" +
" <xs:simpleType>\n" +
" <xs:restriction base=\"xs:string\">\n" +
" <xs:pattern value=\"STU-[0-9]{5}\"/>\n" +
" </xs:restriction>\n" +
" </xs:simpleType>\n" +
" </xs:element>\n" +
" <xs:element name=\"FullName\" type=\"xs:string\"/>\n" +
" </xs:sequence>\n" +
" <xs:attribute name=\"academicYear\" type=\"xs:int\" use=\"required\"/>\n" +
" </xs:complexType>\n" +
" </xs:element>\n" +
"</xs:schema>";
// Defective XML: FullName is placed before StudentId, and academicYear attribute is missing
String defectiveXml = "<StudentRecord>\n" +
" <FullName>Nikita Sharma</FullName>\n" +
" <StudentId>INVALID-FORMAT</StudentId>\n" +
"</StudentRecord>";
// Evaluating matchesXsd(...) against defectiveXml throws SAXParseException:
// matchesXsd(new StringReader(xsdGrammar)).matches(defectiveXml);
}
// ==========================================================================
// DIAGNOSTIC SAXPARSEEXCEPTION FAILURE REPORT GENERATED:
// ==========================================================================
// java.lang.AssertionError: 1 expectation failed.
// Response body doesn't match expectation.
// Expected: The content to match the given a XML schema.
// Actual: <StudentRecord>
// <FullName>Nikita Sharma</FullName>
// <StudentId>INVALID-FORMAT</StudentId>
// </StudentRecord>
//
// ROOT CAUSE BREAKDOWN IN TRACE:
// org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'FullName'.
// One of '{"":StudentId}' is expected. (Line 2, Column 15)
//
// org.xml.sax.SAXParseException: cvc-complex-type.4: Attribute 'academicYear' must appear on element 'StudentRecord'.
}
W3C XML SCHEMA (XSD) SPECIFICATION MATRIX:
βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β XSD CONSTRUCT / METHOD β REST ASSURED DSL SIGNATURE β ARGUMENT TYPE β PRIMARY OPERATIONAL PURPOSE β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Classpath XSD Matcher β matchesXsdInClasspath(path) β String path β Resolves XSD from resources β
β File Handle Matcher β matchesXsd(File file) β java.io.File β Resolves XSD from disk path β
β InputStream Matcher β matchesXsd(InputStream in) β java.io.Stream β Streams XSD from input stream β
β Reader Handle Matcher β matchesXsd(Reader reader) β java.io.Reader β Reads XSD from StringReader β
β String Schema Matcher β matchesXsd(String xsd) β XML String β Validates against inline XSD β
β xs:sequence β <xs:sequence> ... β XSD Grammar β Enforces strict element order β
β xs:all β <xs:all> ... β XSD Grammar β Elements can appear any order β
β xs:choice β <xs:choice> ... β XSD Grammar β Exactly one element allowed β
β minOccurs / maxOccurs β minOccurs="0" maxOccurs="unb"β Cardinality β Controls collection limits β
β xs:pattern β <xs:pattern value="^STU-.."/>β Regex Facet β Enforces character patterns β
β xs:enumeration β <xs:enumeration value=".."/>β Enum Constants β Restricts to allowed values β
β xs:attribute β use="required"|"optional" β XML Attribute β Validates tag attributes β
β targetNamespace β targetNamespace="https://.." β Namespace URI β Binds canonical schema URI β
β FEATURE_SECURE_PROC β XMLConstants.FEATURE_SECURE..β JAXP Feature β Blocks XXE entity injection β
βββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββ€
β TOP 5 XML SCHEMA VALIDATION BEST PRACTICES: β
β 1. Store XSD files in src/test/resources/schemas/: Maintain W3C schemas in version control with tests. β
β 2. Embed matchesXsdInClasspath() in ResponseSpecBuilder: Standardize XML contract checks globally. β
β 3. Enforce elementFormDefault="qualified": Ensure child tags correctly resolve to the targetNamespace. β
β 4. Combine XSD with XPath assertions: Validate grammar with XSD, then check business data with XPath. β
β 5. Lock down XXE external entity resolution: Never allow untrusted remote DTD references in parsers. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ