This project is a Java library to ease up the reading of XSD files.
- Supports Java 17 or higher
- Supports Jakarta XML Binding 4.0
Add following dependency to your project. Replace the value of the attribute version
according to the used
version in your project.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
...
<dependencies>
<dependency>
<groupId>de.elomagic</groupId>
<artifactId>xsd-model</artifactId>
<version>[3,]</version>
</dependency>
</dependencies>
...
</project>
import de.elomagic.xsdmodel.XsdReader;
import de.elomagic.xsdmodel.elements.XsdSchema;
import java.nio.file.Paths;
class Sample {
void example() throws Exception {
System.setProperty(XsdSchemaFactory.XSD_SCHEMA_FACTORY_CLASS, XsdSchemaFactoryMock.class.getName());
XsdSchema schema = XsdReader.read(Paths.get("root2.xsd"));
Assertions.assertEquals("Documentation of the schema annotation.", schema.getAnnotation().getDocumentation().getValue());
Assertions.assertEquals(12, schema.getComplexTypes().size());
}
}
Very experimental implementation of mapping a XSD to key a map.
import de.elomagic.xsdmodel.XsdReader;
import de.elomagic.xsdmodel.converter.Xsd2KeyValueConverter;
import java.nio.file.Paths;
class Sample {
void example() throws Exception {
Xsd2KeyValueConverter<KeyProperties> converter = new Xsd2KeyValueConverter<>()
.setKeyDelimiter(".")
.setAttributeDelimiter("#")
.setAttributeSupport(true)
.setKeyPropertySupplier(KeyProperties::new);
Map<String, KeyProperties> map = converter.convert(getClass().getResourceAsStream("/example.xsd"));
map.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(e -> System.out.println(e.getKey() + "=" + e.getValue().getDatatype()));
}
}
- No repetition support
- No attribution support
- No recursive element type support
- Simple restriction support
What you need is an installed JDK at least version 17 and Apache Maven.
Then clone this project to your local file system and execute mvn clean install
in the project folder. After successful finish you find
the artefact in the target
folder.
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Versioning follows the semantic of Semantic Versioning 2.0.0
Execute following steps:
- Are the CHANGELOG.md up to date?
- Check the version in the
pom.xml
and CHANGELOG.md - Set release date in the CHANGELOG.md
- Execute GitHub action "release"
- Repo owner or admin
The xsd-model is distributed under Apache License, Version 2.0