XML/JSON Schema Helper
A VS Code extension to help you work with XML and schema formats by providing tools to generate XSD schemas from XML examples and convert XSD schemas to JSON schemas.
Features
1. Generate XSD Schema from XML
Automatically generate an XSD (XML Schema Definition) from an XML example file. The extension analyzes the XML structure, including:
- Elements and their hierarchy
- Attributes
- Data types (string, integer, decimal, boolean, date)
- Cardinality (minOccurs, maxOccurs)
2. Convert XSD to JSON Schema
Convert existing XSD schemas to JSON Schema format (Draft 07), making it easier to validate JSON documents or integrate with JSON-based tools.
Usage
Generate XSD from XML
- Open an XML file in VS Code
- Open the Command Palette (
Cmd+Shift+P on macOS, Ctrl+Shift+P on Windows/Linux)
- Type and select:
XML: Generate XSD Schema from XML
- A new document will open with the generated XSD schema
Example:
Given this XML:
<?xml version="1.0"?>
<person>
<name>John Doe</name>
<age>30</age>
<email>john@example.com</email>
</person>
The extension generates:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element ref="name" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="age" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="email" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- Additional element definitions... -->
</xs:schema>
Convert XSD to JSON Schema
- Open an XSD file in VS Code
- Open the Command Palette (
Cmd+Shift+P on macOS, Ctrl+Shift+P on Windows/Linux)
- Type and select:
XSD: Convert XSD to JSON Schema
- A new JSON document will open with the generated JSON schema
Example:
Given an XSD schema, the extension converts it to JSON Schema format:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "person",
"properties": {
"name": {
"type": "array"
},
"age": {
"type": "array"
},
"email": {
"type": "array"
}
}
}
Commands
This extension contributes the following commands:
XML: Generate XSD Schema from XML - Generate XSD schema from the active XML document
XSD: Convert XSD to JSON Schema - Convert XSD schema to JSON Schema format
Requirements
- VS Code version 1.80.0 or higher
Installation
From Source (Development)
- Clone or download this repository
- Navigate to the extension directory
- Run
npm install to install dependencies
- Press
F5 to open a new VS Code window with the extension loaded
Manual Installation
- Package the extension:
vsce package
- Install the
.vsix file in VS Code: Extensions → Install from VSIX
Known Limitations
- The XML to XSD generator creates a basic schema structure. Complex XML patterns may require manual refinement.
- Type inference is based on simple heuristics (e.g., numeric values, booleans, dates).
- The XSD to JSON Schema converter supports common XSD constructs but may not handle all advanced features.
- Generated schemas use
ref attributes for element references, which may need adjustment for some use cases.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
ISC
Author
Meatyhippo