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

  • SEARCH
  • Home
  • 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 6807737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:52:08+00:00 2026-05-26T19:52:08+00:00

I want XML like this: <simple>Foo</simple> I can do this successfully via a JAXB

  • 0

I want XML like this:

<simple>Foo</simple>

I can do this successfully via a JAXB class that looks like this:

@XmlRootElement(name="simple")
class Simple {
    @XmlValue
    public String contents;
}

But now I need to make the Simple class be a subclass of another class like so:

@XmlRootElement(name="simple")
class Simple extends OtherClass {
    @XmlValue
    public String contents;
}

That fails with @XmlValue is not allowed on a class that derives another class. I can’t easily refactor the superclass away (because of the way we’re using @XmlElementRef on a wrapper class). Is there a workaround that will let me annotate my subclass to generate that simple XML?

  • 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-26T19:52:09+00:00Added an answer on May 26, 2026 at 7:52 pm

    Note: I’m the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.

    This use case is supported by MOXy, and IMHO should be supported by the JAXB RI as well:

    Simple

    This class has a field mapped with @XmlValue and extends OtherClass:

    package forum809827;
    
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlValue;
    
    @XmlRootElement(name="simple")
    class Simple extends OtherClass {
    
        @XmlValue
        // @XmlValueExtension
        // As of moxy 2.6, XmlValueExtension needs to be added for this to work
        public String contents;
    
    }
    

    OtherClass

    This is the super class. In MOXy the subclass can map a field/property with @XmlValue as long as the super class does not have any mappings to an XML element:

    package forum809827;
    
    import javax.xml.bind.annotation.XmlAttribute;
    
    public class OtherClass {
    
        @XmlAttribute
        public String other;
    
    }
    

    Demo

    package forum809827;
    
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            JAXBContext jc = JAXBContext.newInstance(Simple.class);
    
            Simple simple = new Simple();
            simple.contents = "FOO";
            simple.other = "BAR";
    
            Marshaller marshaller = jc.createMarshaller();
            marshaller.marshal(simple, System.out);
        }
    
    }
    

    Output

    <?xml version="1.0" encoding="UTF-8"?>
    <simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" other="BAR">FOO</simple>
    

    For More Information on Specifying MOXy as Your JAXB Provider

    • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I want to parse some XML that looks like this: <node> This is <child>
My xml looks like this: <nodes><skus><sku>abc</sku><sku>def123</sku></skus></nodes> I want to get all the elements with
I want to transform an XML document. The source XML looks like this: <svc:ElementList>
I've got an XML doc to deal with that contains attributes like: <action name=foo
So I have an XML file that looks a little like this <xml> <post>
I want use php simple xml parse some tree like this. how to plus
Given an XML structure like this: <garage> <car>Firebird</car> <car>Altima</car> <car>Prius</car> </garage> I want to
I got a row structure looks like ID bigint, ScanRept XML I want to
With a simple XML like this <value> <num> <accession>111</accession> <sequence>AAA</sequence> <score>4000</score> </num> </value> I

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.