Overview
Introduction
Testing that a parser correctly rejects bad input means having bad input to test with.
This tool generates it on demand from a valid starting document.
What Is XML Error Injector?
A test-fixture generator that applies one random well-formedness-breaking mutation to otherwise-valid XML.
The mutation is chosen from a small set of realistic error patterns.
How XML Error Injector Works
The input is first validated (it must be well-formed to start).
A set of mutation strategies is tried in random order until one actually changes the input, each strategy targets a specific class of error (unclosed tags, mismatched tags, unescaped entities, unquoted attributes).
When To Use XML Error Injector
Use it to build negative test cases for a parser or validator.
It's also useful for demonstrating what a specific kind of XML error looks like.
Often used alongside XML Validator and XML Prettifier.
Features
Advantages
- Generates realistic, specific error patterns rather than random text corruption.
- Tells you exactly what kind of error was introduced.
- Runs entirely client-side.
Limitations
- Requires well-formed input to start.
- The mutation applied is random each time, run it multiple times if you need a specific error type.
Examples
Best Practices & Notes
Best Practices
- Run this multiple times if you need to test several different error types, one call applies exactly one mutation.
- Use the XML Validator afterward to confirm the output actually fails validation the way you expect.
- Save a few generated variants as a small negative-test-case suite rather than regenerating on every test run.
Developer Notes
Mutation strategies are tried in shuffled order until one produces a change, so the same input can produce different error types across runs rather than always favoring one strategy.
XML Error Injector Use Cases
- Building negative test cases for an XML parser or validator
- Demonstrating a specific class of XML syntax error
- Fuzz-testing error handling in an XML ingestion pipeline
Common Mistakes
- Expecting this to work on already-invalid XML, input must be well-formed first.
- Assuming the same mutation type is applied every time, it's chosen randomly on each run.
Tips
- Use the XML Validator afterward to confirm the output actually fails validation the way you expect.
- Check the FAQ above if the output doesn't look like what you expected.