Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6355279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:43:58+00:00 2026-05-24T22:43:58+00:00

Is there an XML Schema type to Java data type binding for java.lang.Object in

  • 0

Is there an “XML Schema type to Java data type” binding for java.lang.Object in JAXB?

Simple Example

    <Channels>
      <EChannel>
        <Number>1</Number>
        <Format>0</Format>
        <VarNumber>11</VarNumber>
        <Name>First Channel</Name>
        <ChannelHandler></ChannelHandler>
      </EChannel>
      <EChannel>
        <Number>2</Number>
        <Format>0</Format>
        <VarNumber>22</VarNumber>
        <Name>Second Channel</Name>
        <ChannelHandler></ChannelHandler>
      </EChannel>
    </Channels>

Basically I’ll first unmarshall the xml tree into an arraylist of Pojos (List)

And then in runtime I want to attach a java object to the ChannelHandler property.

I dont want to do anything manually inside the EChannel POJO, since I want these to be generated automatically using xjc

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:43:59+00:00Added an answer on May 24, 2026 at 10:43 pm

    Using @XmlAnyElement(lax=true) on a property of type Object should give you the behavior you are looking for.

    When starting from an XML schema, a schema structure like the following will result in this annotation.

    <xs:element name="ChannelHandler">
        <xs:complexType>
            <xs:sequence>
                <xs:any processContents="lax"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    

    Full XML Schema

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
        <xs:element name="Channels">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="EChannel" maxOccurs="unbounded">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="Number" type="xs:int"/>
                                <xs:element name="Format" type="xs:int"/>
                                <xs:element name="VarNumber" type="xs:int"/>
                                <xs:element name="Name" type="xs:string"/>
                                <xs:element name="ChannelHandler">
                                    <xs:complexType>
                                        <xs:sequence>
                                            <xs:any processContents="lax"/>
                                        </xs:sequence>
                                    </xs:complexType>
                                </xs:element>
                                <xs:any/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>
    

    For More Information

    • http://blog.bdoughan.com/2010/08/using-xmlanyelement-to-build-generic.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this schema and i'm using JAXB to generate java stub files. <?xml
Are there any tools to effectively compare two XML schema's? I have seen some
Is there any defined atom syndication xml schema? RFC 4287 only contains a Relax
Is there a way in an XML schema to specify that an element may
XML Schema specifies occurrence indicators (maxOccurrence, minOccurrence). Is there a best practice in which
I have an existing XML schema that contains a type that I would like
I need to build an XML document from a Java object hierarchy. Both the
In Java, we work a lot with JAXB2. Object<->XML mappings are defined as annotations
I have two XML examples that I want to write a schema for: Example
I've got the following simple XSD document ( foo.xsd ): <?xml version=1.0 encoding=UTF-8?> <xsd:schema

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.