Throaway454534t45
Throaway454534t45

Reputation: 1

How to deal with changes in the XML Schema (XSD)

I'm using MOXy to create Dynamic Entities based on an XSD like so:

FileInputStream xsdIn = new FileInputStream("customer.xsd");
    DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(xsdIn, new MyEntityResolver(), null, null);
    
    //Unmarshaller unmarshaller = (Unmarshaller) jaxbContext.createUnmarshaller();
    JAXBUnmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    
    
    FileInputStream xmlInputStream = new FileInputStream("dynamicjaxb/customer.xml");
    
    //Unmarshall
    DynamicEntity customer = (DynamicEntity) unmarshaller.unmarshal(xmlInputStream);
    System.out.println(customer.<String> get("name"));

And this is my XSD that I cannot change:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:add="http://www.example1.org/address" 
xmlns="http://www.example1.org/customer"
targetNamespace="http://www.example1.org/customer"
elementFormDefault="qualified">

<xsd:element name="customer">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string" minOccurs="0" />
            <xsd:element name="address" type="add:address"
                minOccurs="0" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element> </xsd:schema>

My question is what happens if the XSD file changes and, for example, the element namechanges to something like firstName?*

What I'm basically saying is, how do I deal, dynamically, with changes in an XSD file that I do not control?

Upvotes: 0

Views: 960

Answers (1)

Dijkgraaf
Dijkgraaf

Reputation: 11527

You can't dynamically deal with changes in a XSD that someone else controls, as they could do multiple changes and no automated system method will be smart enough to cope.

Usually what happens if a schema is changed with a breaking change (e.g. renaming or deleting an existing item, changing from optional to mandatory etc.), then the party that controls the change should publish it as a new major version, allowing people still to use the old version for a period of time while they transition to the new one.

If it is a non-breaking change (e.g. adding an optional item or changing something from mandatory to optional), then they might elect to publish it as a minor version change and it comes into effect immediately, as it should not cause any issues for existing systems.

Upvotes: 1

Related Questions