Quantcast
Channel: JAXB 2.x: How to unmarshal an XML without knowing the target class? - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by Fabian Tschachtli for JAXB 2.x: How to unmarshal an XML without knowing the target class?

$
0
0

Every XML Documents Must Have a Root Element and if you want to use the same UnMarshaller for both instances your only possibility is to have a common root element such as:

<root>
  <A></A>
</root>

and your xsd File would look like this

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:annotation>
        <xs:documentation>
        example for stackoverflow
    </xs:documentation>
    </xs:annotation>
    <xs:element name="root" type="rootType"/>
    <xs:complexType name="rootType">
            <xs:choice>
                <xs:element name="A" type="AType"/>
                <xs:element name="B" type="BType"/>
            </xs:choice>
    </xs:complexType>

    ... your AType and BType definitions here

</xs:schema>

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>