How-to
How to open an XSD file
An XSD file is an XML Schema written as plain-text XML, so any text editor can open it: on a Mac, right-click it and choose Open With > TextEdit; on Windows, choose Open with > Notepad. To understand it, open it in an XML-aware editor or XSD viewer that shows the structure, and keep every file it includes or imports in the same folder.
1. What is an XSD file?
An XSD file is an XML Schema Definition: a W3C-standard description of what a valid XML document may contain. It lists the allowed elements and attributes, their order, how often each may appear, and the data type of each value. Partners, government portals, and API specifications often send one alongside sample XML so you can build or check files that match.
The schema is itself an XML document, which is why it opens in any text editor. The first lines usually look like the example below: an XML declaration, then an xs:schema root element that binds the xs prefix to the XML Schema namespace.
The .xsd extension is also used by some cross-stitch pattern software for its own binary pattern files. If the file does not start with <?xml or <xs:schema, run file pattern.xsd in Terminal. An XML Schema reports as an XML document; anything reported as binary data belongs to another program, and the steps below will not help.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:example:orders"
xmlns="urn:example:orders"
elementFormDefault="qualified">
<xs:include schemaLocation="common.xsd"/>
<xs:element name="order" type="OrderType"/>
<xs:complexType name="OrderType">
<xs:sequence>
<xs:element name="customer" type="xs:string"/>
<xs:element name="total" type="MoneyType"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:positiveInteger" use="required"/>
</xs:complexType>
</xs:schema>
$ file order.xsd
order.xsd: XML 1.0 document text, ASCII text2. How do I open an XSD file on a Mac?
Right-click the file in Finder, choose Open With, then TextEdit. TextEdit shows the schema as plain text, which is enough to read a short schema or copy a value from it.
For anything longer than a screen, use Terminal to make it readable. macOS includes xmllint at /usr/bin/xmllint, so these commands work without installing anything. The first confirms the file is well-formed XML and prints nothing if it is. The second pretty-prints a schema that arrived on one long line. The third lists the named top-level declarations, which is a quick table of contents for the schema.
# Check that the schema is well-formed XML (no output means it is)
xmllint --noout order.xsd
# Pretty-print a minified schema into a new file
xmllint --format order.xsd > order.formatted.xsd
# List the named top-level declarations
xmllint --xpath '/*/*/@name' order.xsd
name="order"
name="OrderType"3. Opening an XSD file on Windows or in a code editor
On Windows, right-click the file, choose Open with, then Notepad for a plain-text view. Visual Studio on Windows opens .xsd files in its XML editor. Visual Studio for Mac is no longer an option: Microsoft retired it on August 31, 2024 and recommends Visual Studio Code on the Mac instead.
Visual Studio Code runs on macOS, Windows, and Linux and highlights .xsd files as XML. Adding the XML extension by Red Hat brings schema-aware features to the XML documents that use the schema: once an XML file is associated with an XSD, through xsi:schemaLocation or a file association in settings, the extension validates it and offers completion and hover documentation drawn from the schema.
4. How to read an XSD once it is open
Most schemas follow the same layout, so you can find what you need by looking for a handful of constructs. Start at the top and work down.
- targetNamespace on xs:schema: the namespace URI that elements in your XML must use. In the example, an order document needs xmlns="urn:example:orders" on its root.
- Top-level xs:element declarations: the elements that can be the root of a valid document. Here only order qualifies.
- Named xs:complexType and xs:simpleType definitions: the reusable shapes. An xs:sequence lists child elements in the order they must appear; xs:choice allows one of several.
- minOccurs, maxOccurs, and use="required": which parts are optional and which repeat. minOccurs="0" makes note optional; use="required" makes the id attribute mandatory.
- xs:annotation and xs:documentation: comments from the schema author. In large industry schemas, this is often where the business meaning of a field is explained.
- xs:include and xs:import: references to other schema files. The next section explains why they matter when you open the file.
5. Keep the included and imported files together
Many real schemas are split across several files. xs:include pulls in another schema with the same target namespace, and xs:import brings in components from a different namespace. Both usually point to the other file with a relative schemaLocation, so it is resolved against the folder of the schema that references it.
When you open just one file from a set, you see references to types that are defined somewhere else, and any tool that compiles the schema fails. Download or unzip the whole schema package and keep its folder structure exactly as delivered. If you move only order.xsd and leave common.xsd behind, xmllint reports the missing file and refuses to compile the schema:
$ xmllint --noout --schema order.xsd order.xml
warning: failed to load external entity "common.xsd"
order.xsd:6: element include: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}include': Failed to load the document 'common.xsd' for inclusion.
WXS schema order.xsd failed to compile6. Check an XML file against the XSD
Often the reason you were sent a schema is to check XML against it. With the whole schema folder in place, the same xmllint command compiles the schema and validates the document. A valid file prints a single confirmation line; an invalid one prints the line number and the rule it breaks.
An XML document can also say which schema it expects. Look for xsi:schemaLocation on the root element, which pairs a namespace URI with a schema file, or xsi:noNamespaceSchemaLocation for schemas without a target namespace. Validators use these as hints, so you can still pass the schema explicitly as shown here.
The XML files that go with the schema open on a Mac the same way: TextEdit for a quick look, or xmllint --format order.xml to indent a file that arrived on one line.
<!-- order.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<order xmlns="urn:example:orders" id="1042">
<customer>Ada Lovelace</customer>
<total currency="GBP">42.50</total>
</order>
$ xmllint --noout --schema order.xsd order.xml
order.xml validates7. Browse the schema as a tree in an XSD viewer
A text editor shows a schema line by line, which gets slow once types reference other types across several files. An XSD viewer shows the same file as a structure you can expand, search, and follow from a reference to its definition.
In XML Lens on a Mac, open, paste, or drag an .xsd file into the XSD Viewer workspace. It shows an expandable structure tree of elements, complex and simple types, attributes, and groups beside the syntax-highlighted source, a Globals view of the top-level declarations, and search across names, types, references, and base types. You can format, minify, edit, and save the schema, and compile it to see diagnostics with source context. Visual XSD Map draws type, reference, inheritance, group, and schema-file relationships; load the schema's local folder so it can resolve xs:include and xs:import. To check an XML file against the schema, use the separate Validate workflow.
8. Limits to keep in mind
Opening a schema is safe, but a few situations need extra care before you trust what you see.
- Remote schemaLocation URLs: some schemas import other files from the web. Offline tools, including xmllint without network access and XML Lens, which does not fetch remote schema resources, need local copies of those files.
- XSD 1.1 features: assertions (xs:assert) and conditional types need an XSD 1.1 processor. xmllint and XML Lens do not claim XSD 1.1 support, so such a schema can fail to compile even though it is correct.
- Generated or very large schemas: industry standards can span dozens of files. Start from the file that declares the root element you need, and follow references from there rather than reading every file.
- Confidential schemas: internal or partner schemas can reveal system details. Prefer local tools over online XSD viewers when the schema is not public.
Common questions
What program opens an XSD file?
Any text editor opens it, because an XSD is plain-text XML: TextEdit on a Mac, Notepad on Windows. For a readable structure, use an XML editor such as Visual Studio Code with the Red Hat XML extension, Visual Studio on Windows, or an XSD viewer such as XML Lens on a Mac.
How do I open an XSD file on a Mac without installing anything?
Right-click it in Finder and choose Open With > TextEdit. In Terminal, xmllint --format file.xsd prints an indented version, and xmllint --noout file.xsd confirms it is well-formed.
Can I open an XSD file online?
Yes, online XSD viewers display a pasted or uploaded schema. They are fine for public standards; for internal or partner schemas, use a local editor or viewer so the file stays on your computer.
What is the difference between an XSD file and an XML file?
An XML file holds data. An XSD file describes the rules that XML data must follow: which elements and attributes are allowed, their order, and their types. Validating checks an XML file against those rules.
Why does my XSD fail to open or compile in a tool?
Usually a file it includes or imports is missing, or a schemaLocation points to a remote URL the tool cannot fetch. Keep the whole schema folder together and download remote dependencies locally.
References
W3C XML Schema Part 0: Primer ↗W3C XML Schema 1.1 Part 1: Structures (include, import, schemaLocation) ↗libxml2 xmllint manual ↗Microsoft: What happened to Visual Studio for Mac? ↗Red Hat vscode-xml: Validation with XSD grammar ↗Try the workflow in XML Lens
XML Lens is a native Mac app for viewing, validating, querying and comparing XML that keeps your files on your Mac. It is listed as XML Editor Lens: XPath on the Mac App Store.
Download XML Lens for MacExplore the relevant Mac workspaces and their capabilities.
View and map XML Schema (XSD) locally on Mac Validate XML and run local XSLT 1.0 on Mac View, read, and format XML on your Mac