Sample XML File Download
Need a sample XML file to test an API, a parser, or a data pipeline? Samples Files has a set of free XML test files that you can download right away, with no registration. It covers small well-formed documents, files with namespaces, a large deeply nested file, a file that validates against an XSD schema, and files that are broken on purpose so you can test error handling. All files are scanned and verified.
For other code formats, check out our selection of Code Files
Pick and Download a Free Sample XML file
Sample1.xml
Simple XML File – 1Kb
Description: A single person record with three child elements. The smallest well-formed XML file you can feed to a parser.
Sample2.xml
Medium Complexity XML – 1Kb
Description: A bookstore with repeating book elements. Good for testing loops, lists, and mapping XML to objects.
Sample3.xml
Complex XML with Attributes – 2Kb
Description: Employee records with id and currency attributes. Use it to test attribute parsing and XPath queries.
Sample4.xml
XML with Namespaces (SOAP) – 2Kb
Description: A SOAP 1.1 request that combines prefixed namespaces, a default namespace, and xsi:nil. Ideal for testing namespace-aware parsers and SOAP clients.
Sample5.xml
Large Nested XML – 1.4MB
Description: A product catalog with 2,000 products nested five levels deep, with variants and reviews. Use it for streaming parsers, performance benchmarks, and upload size limits.
Sample6.xml
XML Valid Against an XSD Schema – 1Kb
Description: A purchase order that passes validation against sample6.xsd. Use it as the happy-path test for schema validation.
Sample6.xsd
XML Schema (XSD) – 2Kb
Description: The schema for sample6.xml. It defines required attributes, xs:date, xs:decimal, xs:positiveInteger, and an email pattern.
Sample7-malformed.xml
Malformed XML (Invalid Structure) – 1Kb
Description: Broken on purpose: it has an unescaped ampersand, a mismatched closing tag, an unquoted attribute, and an unclosed root element. Use it to test parser error handling.
Sample8-schema-invalid.xml
Well-formed but Schema-Invalid XML – 1Kb
Description: Parses fine, but fails six rules in sample6.xsd. Use it for negative tests and to check how your validation errors are reported.
What Is a Sample XML File?
XML (eXtensible Markup Language) is a text format that stores data as a tree of nested elements and attributes. A sample XML file is a ready-made XML document with realistic but fake data. You use it to test code that reads, writes, validates, or transforms XML, without exposing real customer or production data.
A good set of XML test files covers both the happy path and the edge cases. You need files that parse cleanly, files that use namespaces the way real APIs do, files large enough to stress memory, and files that are broken so you can confirm that your code rejects them properly. The files on this page cover all of these cases.
Common Developer Use Cases for XML Test Files
1. API Testing: Many SOAP services, payment gateways, and older REST APIs still use XML. Send sample4.xml as a request body to test your client, or use it to mock a server response in Postman, SoapUI, or your test suite.
2. Schema Validation: Check that your XSD validation accepts good documents and rejects bad ones. Validate sample6.xml (should pass) and sample8-schema-invalid.xml (should fail with six errors) against sample6.xsd.
3. Parser Robustness: Feed sample7-malformed.xml to your parser and confirm that it raises a clear error instead of crashing, hanging, or silently returning partial data. Use sample5.xml to check that your parser handles deep nesting and large inputs.
4. Integration Pipelines: Use these files as fixtures in ETL jobs, message queues, and CI pipelines that import, transform (XSLT), or convert XML to JSON or a database. A fixed set of known inputs makes regressions easy to spot.
Which Sample XML File Should You Use?
| File | Variant | Best for |
|---|---|---|
| sample1.xml | Small, well-formed | Smoke tests, tutorials, a first parser call |
| sample2.xml / sample3.xml | Repeating elements & attributes | Mapping XML to objects, reading attributes, XPath queries |
| sample4.xml | Namespaces (SOAP) | SOAP/API clients, namespace-aware parsing, XPath with prefixes |
| sample5.xml | Large, deeply nested (1.4 MB) | Streaming parsers, performance and memory tests, upload limits |
| sample6.xml + sample6.xsd | Valid against an XSD schema | Schema validation, contract tests, the happy path |
| sample7-malformed.xml | Malformed (not well-formed) | Parser robustness, error messages, rejecting bad input |
| sample8-schema-invalid.xml | Well-formed but schema-invalid | Validation error reporting, negative tests in CI |
How to Download, Inspect, and Validate an XML Test File
The examples below use xmllint, which ships with libxml2
(preinstalled on macOS and most Linux distributions), plus Python and
JavaScript. The output shown is what you get with the files on this
page.
Step 1: Download the file
Click Download file next to any sample above, or fetch it from the command line. Each file has a stable direct URL, so you can also download it in a CI job.
# Download a single file
curl -O https://samples-files.com/samples/code/xml/sample2.xml
# Download the schema and both files that go with it
curl -O https://samples-files.com/samples/code/xml/sample6.xsd \
-O https://samples-files.com/samples/code/xml/sample6.xml \
-O https://samples-files.com/samples/code/xml/sample8-schema-invalid.xml Step 2: Inspect the structure
Open small files in any text editor or IDE. For large files like sample5.xml, look at the first lines first, or pretty-print the file to see how it is nested.
# Peek at the first lines without loading the whole file
head -n 20 sample5.xml
# Pretty-print (indent) the document
xmllint --format sample3.xml Step 3: Check that it is well-formed
Well-formed XML has one root element, every tag closed and correctly
nested, quoted attributes, and escaped special characters such as &. --noout prints nothing when the file is fine and an error
with a line number when it is not.
$ xmllint --noout sample2.xml
$ echo $?
0
$ xmllint --noout sample7-malformed.xml
sample7-malformed.xml:6: parser error : xmlParseEntityRef: no name
<title>Pride & Prejudice</title>
^ Step 4: Validate against an XSD schema
Being well-formed only means the syntax is correct. To check that the data has the right elements, attributes, and types, validate the file against a schema. Download sample6.xsd and run:
$ xmllint --noout --schema sample6.xsd sample6.xml
sample6.xml validates
$ xmllint --noout --schema sample6.xsd sample8-schema-invalid.xml
Element 'purchaseOrder': The attribute 'orderId' is required but missing.
Element 'orderDate': '15/01/2026' is not a valid value of the atomic type 'xs:date'.
Element 'quantity': '0' is not a valid value of the atomic type 'xs:positiveInteger'.
Element 'price': 'nineteen' is not a valid value of the atomic type 'xs:decimal'.
Element 'color': This element is not expected.
sample8-schema-invalid.xml fails to validate Step 5: Parse it in your code
Python's standard library can parse all of these files. Note the
namespace map for sample4.xml: without it, find() returns
nothing, which is one of the most common XML bugs.
import xml.etree.ElementTree as ET
# 1. Simple file: read child elements
tree = ET.parse("sample2.xml")
for book in tree.getroot().findall("book"):
print(book.findtext("title"), "-", book.findtext("price"))
# 2. Namespaced file: map prefixes to namespace URIs
ns = {"ord": "https://samples-files.com/ns/orders"}
root = ET.parse("sample4.xml").getroot()
for item in root.iterfind(".//ord:Item", ns):
print(item.get("sku"), item.findtext("ord:Description", namespaces=ns))
# 3. Malformed file: make sure your code fails gracefully
try:
ET.parse("sample7-malformed.xml")
except ET.ParseError as e:
print("Invalid XML:", e) # not well-formed (invalid token): line 6, column 22 For large files, use a streaming parser so memory use stays flat:
import xml.etree.ElementTree as ET
# Stream the 1.4 MB catalog instead of loading it all into memory
count = 0
for event, elem in ET.iterparse("sample5.xml", events=("end",)):
if elem.tag == "product":
count += 1
elem.clear() # free memory as you go
print(count, "products") # 2000 products In the browser, use the built-in DOMParser:
// Run in the browser console on this page
const res = await fetch("/samples/code/xml/sample3.xml");
const doc = new DOMParser().parseFromString(await res.text(), "application/xml");
if (doc.querySelector("parsererror")) {
throw new Error("Invalid XML");
}
doc.querySelectorAll("employee").forEach((e) => {
console.log(e.getAttribute("id"), e.querySelector("name").textContent);
}); Download Best Practices
- Use the Download button, not copy and paste. Browsers show XML as a collapsible tree, and copying from that view can change whitespace or drop the XML declaration.
- Keep the encoding as UTF-8. Don't re-save the files in Word or Excel, which can add a BOM or change the encoding and break byte-for-byte tests.
- Commit the files as test fixtures. Keep them in your
repository under a folder like
tests/fixtures/xml/so your tests don't depend on a network download. - Test both valid and invalid input. Pair every happy-path file with a broken one (sample6 with sample8, sample2 with sample7) so you know your error handling actually runs.
- Disable external entities in production parsers. When you parse XML from untrusted sources, turn off DTD and external entity processing to prevent XXE attacks.
Other Sample Code files you may like
Sample JSON Files
Free sample JSON files for testing APIs, data import, and development projects with various data structures.
Sample CSV Files
Download sample CSV files from 10 to 10,000 rows for data import, analysis, and performance testing.
Sample HTML Files
Download sample HTML files for testing browsers, web scrapers, and HTML parsers.
More ideas for using an XML file
1. Configuration Files Utilize XML files as configuration files for your applications. Store settings, parameters, and preferences in a structured XML format, providing a clear and organized way to manage configuration data.
2. Data Interchange Format Employ XML as a data interchange format for seamless communication between different systems. Its hierarchical structure and self-descriptive nature make it an ideal choice for exchanging structured data between applications.
3. Document Markup Use XML for document markup to define structured data within documents. XML tags provide a standardized way to represent data elements, making it easier to organize and process information within textual content.
4. Database Import/Export Integrate XML files for importing or exporting data from databases. XML’s versatility allows you to represent complex data structures, making it a valuable format for transferring data between databases or storing backups.
Frequently Asked Questions About Sample XML Files
What is a sample XML file?
A sample XML file is a ready-made XML document with realistic but fake data. Developers and QA engineers use it to test code that reads, writes, validates, or transforms XML without exposing real customer or production data.
Are these sample XML files free?
Yes. Every XML file on Samples Files is free to download with no registration or sign-up, and you can use them in personal and commercial projects.
What is the difference between well-formed and valid XML?
Well-formed XML follows the basic syntax rules: one root element, every tag closed and correctly nested, quoted attributes, and escaped special characters. Valid XML is well-formed and also matches a schema (XSD or DTD) that defines which elements, attributes, and data types are allowed. sample7-malformed.xml breaks the first rule set; sample8-schema-invalid.xml breaks only the second.
How do I check if an XML file is valid?
Run xmllint --noout file.xml to check that it is well-formed, and xmllint --noout --schema schema.xsd file.xml to validate it against a schema. Most IDEs (VS Code with an XML extension, IntelliJ, Eclipse) and online XML validators do the same checks.
Which XML file should I use for performance testing?
Use sample5.xml. It is about 1.4 MB with 2,000 products nested five levels deep, which is large enough to show the difference between DOM parsing and streaming parsers like SAX, StAX, or Python's iterparse.
If you want to know more about the XML Format you can find more information here.