Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting xsd restrictions of specific xml element

Tags:

java

xml

xsd

Is it possible to get restrictions of specific element when I'm parsing XML file in Java?

For example, if I have a schema:

<xs:element name="MyString" minOccurs="0">
  <xs:simpleType>
   <xs:restriction base="xs:string">
    <xs:maxLength value="100"/>
   </xs:restriction>
  </xs:simpleType>
</xs:element>

when I get node MyString during XML file parsing I want to be able to acquire information that its restrictions are xs:string and maxLength = 100.

like image 202
Krzysztof Atłasik Avatar asked Jan 19 '26 01:01

Krzysztof Atłasik


2 Answers

I would recommend this project.

It is the same jaxb plugin as Puce linked, but with proper maven project and some improvements.

like image 62
Meo Avatar answered Jan 20 '26 15:01

Meo


You could look for/ write a JAXB plugin to generate Bean Validation Annotations (JSR-303), e.g.:

http://metro.1045641.n5.nabble.com/JAXB-plugin-to-generate-Bean-Validation-Annotations-JSR-303-td5598189.html

like image 28
Puce Avatar answered Jan 20 '26 15:01

Puce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!