https://github.com/elomagic/xsd-model
Object model of the XSD
https://github.com/elomagic/xsd-model
binding jarkartaee java java17 xsd
Last synced: 6 months ago
JSON representation
Object model of the XSD
- Host: GitHub
- URL: https://github.com/elomagic/xsd-model
- Owner: elomagic
- License: apache-2.0
- Created: 2017-08-30T15:53:26.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-04-09T14:45:29.000Z (6 months ago)
- Last Synced: 2025-04-09T15:45:04.847Z (6 months ago)
- Topics: binding, jarkartaee, java, java17, xsd
- Language: Java
- Homepage:
- Size: 463 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# xsd-model - Simple object model of the XSD file
---
[][license]
[](https://mvnrepository.com/artifact/de.elomagic/xsd-model)
[](https://github.com/elomagic/xsd-model/actions)
[](https://github.com/elomagic/xsd-model/issues)
[](https://GitHub.com/elomagic/xsd-model/tags/)
[](https://github.com/elomagic/xsd-model/graphs/commit-activity)
[](https://www.buymeacoffee.com/elomagic)## What is this xsd-model ? ###
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## Using the library
### Maven
Add following dependency to your project. Replace the value of the attribute ```version``` according to the used
version in your project.```xml
...
de.elomagic
xsd-model
[3,]
...
```
## Using the API
### Read a XSD file
```java
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());
}
}
```### Convert XSD to key map
Very experimental implementation of mapping a XSD to key a map.
```java
import de.elomagic.xsdmodel.XsdReader;
import de.elomagic.xsdmodel.converter.Xsd2KeyValueConverter;import java.nio.file.Paths;
class Sample {
void example() throws Exception {
Xsd2KeyValueConverter converter = new Xsd2KeyValueConverter<>()
.setKeyDelimiter(".")
.setAttributeDelimiter("#")
.setAttributeSupport(true)
.setKeyPropertySupplier(KeyProperties::new);Map map = converter.convert(getClass().getResourceAsStream("/example.xsd"));
map.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(e -> System.out.println(e.getKey() + "=" + e.getValue().getDatatype()));
}
}
```#### Limitations
* No repetition support
* No attribution support
* No recursive element type support
* Simple restriction support## How to build artefact by myself?
What you need is an installed JDK at least version 17 and [Apache Maven](https://maven.apache.org).
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.## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Versioning
Versioning follows the semantic of [Semantic Versioning 2.0.0](https://semver.org/)
### Releasing new version / hotfix (Only for users who have repository permissions)
#### Releasing new version / hotfix
Execute following steps:
* Are the [CHANGELOG.md](https://github.com/elomagic/xsd-model/blob/main/CHANGELOG.md) up to date?
* Check the version in the ```pom.xml``` and [CHANGELOG.md](https://github.com/elomagic/xsd-model/blob/main/CHANGELOG.md)
* Set release date in the [CHANGELOG.md](https://github.com/elomagic/xsd-model/blob/main/CHANGELOG.md)
* Execute GitHub action "release"## Who do I talk to? ###
* Repo owner or admin
## License
The xsd-model is distributed under [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
[license]: https://www.apache.org/licenses/LICENSE-2.0