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 8479725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:06:43+00:00 2026-06-10T19:06:43+00:00

How can I realize this XML with JAXB? Currently the expires attribute in the

  • 0

How can I realize this XML with JAXB? Currently the expires attribute in the grantA,C,B elements is not bounded – but it should. I don’t know how to associate an element with an attribute. Do I have to create classes for every grantA,C,B?
XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <customers>
        <customer>
            <name>C1</name>
            <grantA expires="">false</grantA>
            <grantB expires="">true</grantB>
            <grantC expires="">true</grantC>
        </customer>
        <customer>
            <name>C2</name>
            <grantA expires="">false</grantA>
            <grantB expires="">true</grantB>
            <grantC expires="">true</grantC>
        </customer>
        <customer>
            <name>C3</name>
            <grantA expires="">false</grantA>
            <grantB expires="">true</grantB>
            <grantC expires="">false</grantC>
        </customer>
    </customers>

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="name" type="xs:string" />

    <xs:element name="grantA" type="xs:boolean" />
    <xs:element name="grantB" type="xs:boolean" />
    <xs:element name="grantC" type="xs:boolean" />

    <xs:element name="customers" type="customers" />
    <xs:element name="customer">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="name" />
                <xs:element name="grantA">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:string">
                                <xs:attribute name="expires" type="xs:string" />
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
                <xs:element name="grantB">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:string">
                                <xs:attribute name="expires" type="xs:string" />
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
                <xs:element name="grantC">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:string">
                                <xs:attribute name="expires" type="xs:string" />
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="customers">
        <xs:sequence>
            <xs:element ref="customer" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
</xs:schema>

My current state is:

Customers.java:

@XmlRootElement(name = "customers")
public class Customers
{
    private List<Customer>  customerList;

    @XmlElement(name = "customer")
    public List<Customer> getCustomerList()
    {
        if (null == customerList)
        {
            customerList = new ArrayList<Customer>();
        }
        return customerList;
    }

    public void setCustomerList(List<Customer> customers)
    {
        this.customerList = customers;
    }

}

Customer.java

@XmlRootElement(name = "customer")
@XmlType(propOrder = { "name", "grantA", "grantB", "grantC" })
public class Customer
{
    private String  name = "";
    private boolean grantA;
    private boolean grantB;
    private boolean grantC;

    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)   
    @XmlElement(name = "name", required=true)
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    @XmlElement(name = "grantA", required=true)
    public boolean isGrantA()
    {
        return grantA;
    }

    public void setGrantA(boolean grantA)
    {
        this.grantA = grantA;
    }



    @XmlElement(name = "grantB", required=true)
    public boolean isGrantB()
    {
        return grantB;
    }

    public void setGrantB(boolean grantB)
    {
        this.grantB = grantB;
    }

    @XmlElement(name = "grantC", required=true)
    public boolean isGrantC()
    {
        return grantC;
    }

    public void setGrantC(boolean grantC)
    {
        this.grantC = grantC;
    }


    @Override
    public String toString()
    {
        return "" + name + "[ " + grantA + ", " + grantB + " " + grantC + " ]";
    }

}
  • 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-06-10T19:06:45+00:00Added an answer on June 10, 2026 at 7:06 pm

    You could create a single class, Grant, like this:

    @XmlType
    public class Grant {
        @XmlAttribute
        private String expires;
    
        @XmlValue
        private boolean value;
    
        //getters and setters
    }
    

    and in the Customer class map it with different names, like this:

    public class Customer
    {
        private String  name = "";
        @XmlElement(name="grantA");
        private Grant grantA;
    
        @XmlElement(name="grantB");
        private Grant grantB;
    
        @XmlElement(name="grantC");
        private Grant grantC;
    
        //rest of the code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize this is a repost but I needed to as I can't use
What's wrong with this xml schema? It doesn't parse correctly, and I can't realize
I just can't realize why my read time out is not working. All I
I understand the differences between XML and HTML, but one particular aspect is not
I realize that this might be a duplicate question but this question is very
Wondering if anyone can help me with this annoying but trivial (in terms of
I realize this has been asked countless times, but I have yet to come
Ok, I know this can't be hard, but I'm having a heck of a
I realize that without code this might be hard to answer but the problem
I was wondering how I can realize with jQuery the simple example in the

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.