How to use JAXB to process messages from two separate schemas (with same rootelement name)

Posted by sairn on Stack Overflow See other posts from Stack Overflow or by sairn
Published on 2011-03-09T17:41:31Z Indexed on 2011/03/10 16:10 UTC
Read the original article Hit count: 265

Filed under:

Hi

We have a client that is sending xml messages that are produced from two separate schemas.

We would like to process them in a single application, since the content is related.

We cannot modify the client's schema that they are using to produce the XML messages...

We can modify our own copies of the two schema (or binding.jxb) -- if it helps -- in order to enable our JAXB processing of messages created from the two separate schemas.

Unfortunately, both schemas have the same root element name (see below).

QUESTION: Does JAXB prohibit absolutely the processing two schemas that have the same root element name?
-- If so, I will stop my "easter egg" hunt for a solution to this... ---Or, is there some workaround that would enable us to use JAXB for processing these XML messages produced from two different schemas?

schema1 (note the root element name: "A"):

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">
    <xsd:element name="A">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="AA">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="AAA1" type="xsd:string" />
                            <xsd:element name="AAA2" type="xsd:string" />
                            <xsd:element name="AAA3" type="xsd:string" />
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="BB">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="BBB1" type="xsd:string" />
                            <xsd:element name="BBB2" type="xsd:string" />
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

schema2 (note, again, using the same root element name: "A")

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">
    <xsd:element name="A">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="CCC">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="DDD1" type="xsd:string" />
                            <xsd:element name="DDD2" type="xsd:string" />
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="EEE">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="EEE1">
                                <xsd:complexType>
                                    <xsd:sequence>
                                        <xsd:element name="FFF1" type="xsd:string" />
                                        <xsd:element name="FFF2" type="xsd:string" />
                                    </xsd:sequence>
                                </xsd:complexType>
                            </xsd:element>
                            <xsd:element name="EEE2" type="xsd:string" />
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

© Stack Overflow or respective owner

Related posts about jaxb