The XSD Creator is a Python-based tool designed to generate XSD schemas from XML files and validate XML files against their corresponding XSD schemas. It also includes a utility to download XML files from URLs specified in a CSV file.
- Generate XSD Schemas: Automatically create XSD schemas from XML files.
- Validate XML Files: Validate XML files against their corresponding XSD schemas.
- Batch Processing: Process multiple XML files in a folder.
- Type Strictness: Optionally enable strict type inference for XSD generation.
- Download XML Files: Download XML files from URLs specified in a CSV file.
To use the XSD Creator, ensure the following dependencies are installed:
- Python 3.7 or higher
- Required Python Libraries:
lxmlrequests
Install the required libraries using pip:
pip install -r requirements.txt-
Clone the repository:
git clone <repository-url> cd xsd_creator
-
Install dependencies:
pip install -r requirements.txt
-
Ensure the following folder structure exists:
xsd_creator/ ├── xmlgen/ # Contains the XSD generation logic │ ├── xsd_generator.py # Core logic for generating XSD schemas │ ├── xml_parser.py # XML parsing utilities │ ├── schema_inferer.py # Type inference for XSD generation ├── xsd_creator.py # Main script for creating and validating XSDs ├── urls.csv # CSV file with URLs for XML downloads ├── download_xml.py # Script to download XML files from URLs ├── xml_files/ # Folder to store XML files ├── xsd_files/ # Folder to store generated XSD files └── readme.me # Documentation for the project
The XSD Creator can be used via the command line. Below are the available options and examples.
| Option | Description |
|---|---|
-c, --create |
Create an XSD schema from the specified XML file or all XML files in a folder. |
-v, --validate |
Validate the specified XML file or all XML files in a folder against their corresponding XSD schemas. |
-f, --file |
Path to a specific XML file to process. |
-l, --list |
Process all XML files in the specified folder. |
-t, --typestrict |
Enable strict type checking when creating XSD schemas. |
-
Generate an XSD schema for a single XML file:
python xsd_creator.py -c -f xml_files/importfeed.xml
-
Validate a single XML file against its XSD schema:
python xsd_creator.py -v -f xml_files/importfeed.xml
-
Generate XSD schemas for all XML files in a folder:
python xsd_creator.py -c -l xml_files
-
Validate all XML files in a folder against their XSD schemas:
python xsd_creator.py -v -l xml_files
-
Enable strict type checking during XSD generation:
python xsd_creator.py -c -f xml_files/importfeed.xml -t
Use the download_xml.py script to download XML files from URLs specified in urls.csv. The downloaded files will be saved in the xml_files folder.
Run the script:
python download_xml.py- If a file or folder is not found, an appropriate error message will be displayed.
- Validation errors will be logged in the console for debugging.
This project is licensed under the MIT License. Feel free to use and modify it as needed.
Contributions are welcome! If you encounter any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.