To validate XML against XSD you need a schema-aware processor, meaning a tool that reads both your XML file and the XSD and compares them. The XML Validator on this site does something earlier and narrower: you paste XML, click validate, and it reports parsing errors and malformed tags. That is the well-formedness check, and a document has to pass it before any schema check can run.
This article separates the two checks, shows how to fix parsing problems first, and then runs a schema check in your own environment with xmllint. The input is an XML document and, for the second step, an XSD file. The output you want is either a parse error with a location or confirmation that the file conforms to your schema.
Table of Contents

How to Validate XML Against XSD in Two Steps
Well-formedness asks whether the text can be parsed under XML syntax rules, which the W3C defines in XML 1.0 Fifth Edition. Schema validation asks a different question: does this well-formed document conform to one particular schema? The W3C XML Schema specifications define that assessment and the datatypes it uses. A file can pass the first check and fail the second, and a failure in the first means the second cannot start.
| Question | Well-formed check | XSD validation |
|---|---|---|
| What it needs | Only the XML text | The XML plus the intended XSD |
| What it catches | Mismatched or unclosed tags, broken attribute quotes, premature end of input | Unexpected or out-of-order elements, wrong typed values, missing required attributes |
| Where to run it | XML Validator and XML Formatter on this site | A schema-aware tool in your own environment |
The practical workflow is simple. Repair parsing errors first, then supply the schema and check structure and values. If you try to validate an XML file against an XSD before the file parses, the processor can only tell you about syntax, so you lose time reading the wrong kind of error.

Step 1: Find Parsing Errors Before You Touch the Schema
Open the XML Validator, paste your XML and click validate. Its description is limited to detecting parsing errors and malformed tags, so treat it as a syntax gate. It does not read an XSD and cannot tell you whether the content matches one. Here is a small file that fails because the closing tag does not match the opening tag:
<order id="A-100"> <item>Notebook</item> <quantity>3</quantity> </orders>
The opening tag is order and the closing tag is orders, so the parser stops. Fix the first reported problem and run the check again, because one unclosed or mismatched element often causes later messages that disappear once it is repaired.
- Paste the XML into the validator and click validate.
- Read the first error and fix that one before looking at the rest.
- Run the check again until no parsing error remains.
- Paste the repaired file into the XML Formatter, click format, and read the indented structure to confirm elements sit where you expect them.
The formatter also reports XML errors, but use it as an inspection aid, not as validation. Indentation adds or changes whitespace, and in mixed content or whitespace-sensitive elements that can change meaning. The validator can also copy or download normalized output, so keep your original file and compare before replacing it. A readable layout proves nothing about element order, required attributes or data types.

What an XSD Adds: Order, Types and Required Attributes
An XSD is a set of rules for one family of documents. It can constrain element order and how often an element occurs, whether an attribute must be present, and which datatype a value must follow. Those rules apply only to documents checked against that schema, not to XML in general. Here is a small schema for an order element with two ordered children, an integer quantity and a required attribute:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="item" type="xs:string"/>
<xs:element name="quantity" type="xs:integer"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
This instance conforms to it:
<order id="A-100"> <item>Notebook</item> <quantity>3</quantity> </order>
This one is perfectly well-formed and will pass the XML Validator, yet a schema check rejects it because the children are reversed:
<order id="A-100"> <quantity>3</quantity> <item>Notebook</item> </order>
Other well-formed variants fail for different reasons:
<quantity>three</quantity>is not a validxs:integer.- Removing
id="A-100"leaves out an attribute declared withuse="required". - Adding a second
itemfails here because the schema declares exactly one. A schema can allow repetition withminOccursandmaxOccurs, and repetition also affects conversion, which is why I wrote about how one element becomes an object while two become an array.
The exact outcome always depends on the schema you supply. Datatype rules come from the W3C XML Schema datatypes specification, and structure rules from the structures specification.
Validate XML Against XSD Locally With xmllint
The XML Validator and XML Formatter do not run XSD checks, so use a schema-aware tool in your own environment. One option is xmllint, the command-line tool that ships with libxml2. After the file parses cleanly, run:
xmllint --noout instance.xml xmllint --noout --schema schema.xsd instance.xml
The first command only parses the file and reports syntax errors, with no schema involved. The second validates the instance against the W3C XML Schema in schema.xsd. --noout suppresses printing the document, so you see only the result. Do not reach for --valid when you mean XSD: the official manual defines it as DTD validation, while --schema is the option for W3C XML Schema.
If your schema depends on features from a specific XSD version, check what your installed xmllint supports before trusting a pass. In scripts, check the exit status as well as the message text. Run the command on files you trust, and note that a schema can import or include other schema files, so confirm where those references resolve.
Before you run an online XML schema validator or a local tool, prepare the file with this short checklist:
- The document passes the well-formed check with no parsing errors.
- You know which XSD is the intended one and which version of it.
- The root element name and namespace match what the schema declares.
- You kept an untouched copy of the original before any formatting.
Reading Errors: Parsing Failures vs Schema Failures
Error wording and line numbers depend on the processor, so do not expect identical messages from every tool. What matters is the category of problem:
- Parsing failures mention things like a mismatched tag, an unclosed element, a premature end of data or a badly quoted attribute. The fix is a syntax repair, and the validator on this site is the right place to find it.
- Schema failures mention an unexpected element, a missing required attribute, an element that is not allowed here, or a value that is not valid for its type. The document parsed fine, so the fix is in the content, the order or the schema itself.
A parse error line number can point after the real cause, because the parser only notices the problem when it reaches text that no longer fits. Start at the reported line and look upward. For a schema failure, compare the message with the matching declaration in the XSD. If the message says an element is unexpected, check both its position in the sequence and its namespace before concluding the data is wrong.
Remember what each result proves. A clean parse does not confirm element order, required schema attributes or data types. A passing schema check does not confirm that values make business sense, only that they fit the declared structure and types.
Namespace Problems That Break Schema Checks
Namespaces are a common reason a well-formed file fails schema validation. If the schema declares a targetNamespace, the element in your instance must be in that namespace. A schema like this one:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://example.com/orders"
elementFormDefault="qualified">
expects an instance such as:
<order xmlns="https://example.com/orders" id="A-100"> <item>Notebook</item> <quantity>3</quantity> </order>
Three rules from the Namespaces in XML specification and the W3C schema primer explain most failures:
- The schema matches namespace URIs, not prefixes.
o:orderand a default-namespaceorderare the same element if they map to the same URI. - Every prefix you use must be declared. If it is not, the file is not even namespace-well-formed, and you will see the undeclared namespace prefix error before any schema check.
- An unprefixed attribute does not inherit the element’s default namespace. It has no namespace, which matters if the schema declares qualified attributes.
For the parsing side of this problem, see my guide to the undeclared namespace prefix error. Do not invent a namespace URI just to silence a message. Use the one defined by the schema or by whoever owns the data format, because a made-up URI can make the file pass parsing while still failing against the real schema.
Frequently asked questions
How do I validate an XML file against an XSD?
First make sure the file is well-formed, which you can check with the XML Validator on this site. Then use a schema-aware tool in your own environment, for example xmllint –noout –schema schema.xsd instance.xml, with the schema that is meant for that document.
Is there an online XML schema validator on this site?
No. The XML Validator detects parsing errors and malformed tags, and the XML Formatter indents the structure. Neither checks element order, data types or required attributes defined in an XSD, so use a schema-aware tool locally for that.
Why does my XML fail schema validation when it is well-formed?
Well-formed only means the syntax parses. The schema may require a different element order, a typed value such as an integer, a required attribute or a specific namespace. Compare the schema error with the matching declaration in the XSD.
What is the difference between a parsing error and a schema error?
A parsing error means the text breaks XML syntax, such as a mismatched tag or premature end of data. A schema error means the document parsed but does not conform to the XSD, for example an unexpected element or a missing required attribute. Exact wording depends on the processor.
Does xmllint –valid check an XSD?
No. In the official xmllint manual, –valid performs DTD validation. Use –schema schema.xsd for W3C XML Schema validation, and check that your installed version supports the schema features you rely on.
Do namespace prefixes have to match the ones in the schema?
No. The schema matches namespace URIs, so the prefix you choose does not matter as long as it is declared and maps to the correct URI. Remember that an unprefixed attribute does not inherit the default namespace of its element.
Can formatting my XML change whether it validates?
It can, in some cases. Formatting adds or changes whitespace, which can matter in mixed content or elements whose text is significant. Format a copy for reading, keep the original, and run the schema check on the file you actually intend to use.
Next steps
To validate XML against XSD, treat it as two checks. Use the XML Validator to fix mismatched or unclosed tags and other parsing errors, use the formatter to read the structure, and keep your original file. Then run a schema-aware command such as xmllint --noout --schema schema.xsd instance.xml with the intended XSD and the correct namespace mapping. Your next step: take one real file, repair it until it parses, and run it against its schema locally.
Related tools and resources on HTML Editor Online:
- XML Validator
- XML Formatter
- XML Undeclared Namespace Prefix Error
- XML to JSON Single Element Object Multiple Elements Array
Sources and further reading
- Extensible Markup Language (XML) 1.0 (Fifth Edition)
- XML Schema Part 1: Structures Second Edition
- XML Schema Part 0: Primer Second Edition
- xmllint
- XML Schema Part 2: Datatypes Second Edition
- XML Validator – Free Online XML Validator | HTML Editor Online
- XML Formatter
- Namespaces in XML 1.0 (Third Edition)
- XML Undeclared Namespace Prefix Error