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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:56:24+00:00 2026-06-01T04:56:24+00:00

This is my XML file <BADFM> <Given> <Ord> <Bag IDC=DM /> </Ord> </Given> </BADFM>

  • 0

This is my XML file

   <BADFM>
<Given>
<Ord>
<Bag IDC="DM" />
</Ord>
</Given>
</BADFM>

This is my Parser class

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

public class Test {
    public static void main(String args[]) throws Exception {

        File file = new File("D:\\BADML.xml");
        JAXBContext jaxbContext = JAXBContext
                .newInstance(MyMessage.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        MyMessage authentifyResult = (MyMessage) jaxbUnmarshaller
                .unmarshal(file);
        System.out.println(authentifyResult.getGiven().getOrd().getBag().getIDC());

    }
}

This is MyMessage

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="BADFM")
public class MyMessage
{
@XmlElement(name="Given")
private Given given;

public Given getGiven() {
    return given;
}

public void setGiven(Given given) {
    this.given = given;
}


}

This is Given.java

import javax.xml.bind.annotation.XmlElement;

public class Given {
    private Ord ord;
    @XmlElement(name = "Ord")
    public Ord getOrd() {
        return ord;
    }
    public void setOrd(Ord ord) {
        this.ord = ord;
    }
}

This is Ord.java

 import javax.xml.bind.annotation.XmlElement;

public class Ord {

    private Bag bag;
    @XmlElement(name="Bag")
    public Bag getBag() {
        return bag;
    }

    public void setBag(Bag bag) {
        this.bag = bag;
    }

}

This is Bag.java

  import javax.xml.bind.annotation.XmlAttribute;

public class Bag {
      @XmlAttribute(name="IDC")
    private String IDC ;

    public String getIDC() {
        return IDC;
    }
    @XmlAttribute(name="IDC")
    public void setIDC(String IDC) {
        IDC = IDC;
    }

}

When i ran that i am getting

  Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "IDC"
    this problem is related to the following location:
        at public java.lang.String Bag.getIDC()
        at Bag
        at public Bag Ord.getBag()
        at Ord
        at public Ord Given.getOrd()
        at Given
        at public Given MyMessage.getGiven()
        at MyMessage
    this problem is related to the following location:
        at private java.lang.String Bag.IDC
        at Bag
        at public Bag Ord.getBag()
        at Ord
        at public Ord Given.getOrd()
        at Given
        at public Given MyMessage.getGiven()
        at MyMessage

    at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at Test.main(Test.java:11)
  • 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-01T04:56:26+00:00Added an answer on June 1, 2026 at 4:56 am

    You need to use the @XmlAttribute for the IDC variable of the Bag class. Once you make that change, the XML you referenced at the top will work.

    As for your current code, it is expecting the XML to look like:

    <Bag>
      <IDC>DM</IDC>
    </Bag>
    

    You can easily see what type of XML your classes are expecting by populating all attribute fields and then marshaling the object to a file.

    Update

    You should always declare your attributes as private if you are going to have properly named getters and setters. Otherwise, JAXB will throw the error Class has two properties of the same name.

    When declaring that a class attribute is a @XmlAttribute, you should also put the annotation on the getter so that JAXB does not think you want both a @XmlAttribute and @XmlElement with the same name.

    public class Bag {
        private String IDC ;
    
        @XmlAttribute(name="IDC")
        public String getIDC() {
            return IDC;
        }
    
        public void setIDC(String IDC) {
            this.IDC = IDC;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
I want to use DOM4j for parsing xml file in Java. I have this
Given this XML file: <?xml version=1.0 encoding=UTF-8?> <root> <data> <track clipid=1> <url>http://www.emp3world.com/to_download.php?id=33254</url> <http_method>GET or
I've got this XML file that I am parsing using the parser here and
I have this XML file : http://dl.dropbox.com/u/10773282/2011/perf.xml It has two Class elements as is
Given this XML file: <users blessed=phrogz alians> <user name=phrogz id=42 /> <user name=lachtok id=3
given this xml file, i would like to extract the data out from it.
This XML file contained archived news stories for all of last year. I was
I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...

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.