Search code examples
javaxmlxsdxmlbeans

How to automatically add xsd:attribute to xsd:complexType in Apache XMLBeans?


We're running into some trouble with supplied XSDs of the following kind:

<xsd:complexType name="foo">
    ...
    <xsd:attribute name="version" fixed="1" />
</xsd:complexType>

The XML-Result is then expected look something like this:

<foo version="1">...</foo>

Since this is not how fixed attribute values are actually supposed to work XMLBeans will not generate such a result for us by default. We have hundreds of XSDs like this with varying versions and want to avoid adding them all by hand.

Does anyone know of a way to programmatically determine the values of fixed attributes of a given XMLObject so we can add them generically?


Solution

  • As described in the documentation provided by Petru Gardea's comment above you can access information about an XMLObjects schema, its attributes and their default values by using the SchemaTypeSystem.