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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:21:57+00:00 2026-06-01T10:21:57+00:00

I am working on creating a Java class to map an XML file that

  • 0

I am working on creating a Java class to map an XML file that has multiple same elements. The following XML is an example of what the file looks like:

<TrackBroadcast>
<DateTime>some date</DateTime>
<From>from someone</From>
<To>to someone</To>
<Classification>some type of classification</Classification>
<Command>some type of command</Command>
<MsgId>some id</MsgId>
<Barge attribute1="???" attribute2="???" attribute3="" etc/> --->The Barge.java class explains the attributes
<Barge attribute1="???" attribute2="???" attribute3="" etc/> --->The Barge.java class explains the attributes
<Barge attribute1="???" attribute2="???" attribute3="" etc/> --->The Barge.java class explains the attributes
<Barge attribute1="???" attribute2="???" attribute3="" etc/> --->The Barge.java class explains the attributes
</TrackBroadcast>

My JAXB class can read in the DateTime, From, To, Classification, Command, and MsgId elements but it cannot read in the Barge elements. I have two classes to try to encapsulate the XML but I know I doing something wrong. The two classes are:

@XmlRootElement(name="TrackBroadcast")
public class TrackBroadcast {

    String dataTime;
    String from;
    String to;
    String classification;
    String command;
    String msgId;
    List<Barge> barge = new ArrayList<Barge>();

    public String getDataTime() {
        return dataTime;
    }

    @XmlElement(name="DateTime")
    public void setDataTime(String dataTime) {
        this.dataTime = dataTime;
    }

    public String getFrom() {
        return from;
    }

    @XmlElement(name="From")
    public void setFrom(String from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    @XmlElement(name="To")
    public void setTo(String to) {
        this.to = to;
    }

    public String getClassification() {
        return classification;
    }

    @XmlElement(name="Classification")
    public void setClassification(String classification) {
        this.classification = classification;
    }

    public String getCommand() {
        return command;
    }

    @XmlElement(name="Command")
    public void setCommand(String command) {
        this.command = command;
    }

    public String getMsgId() {
        return msgId;
    }

    @XmlElement(name="MsgId")
    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public List<Barge> getBarge() {
        return barge;
    }

    public void setBarge(List<Barge> barge) {
        this.barge = barge;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final TrackBroadcast other = (TrackBroadcast) obj;
        if ((this.dataTime == null) ? (other.dataTime != null) : !this.dataTime.equals(other.dataTime)) {
            return false;
        }
        if ((this.from == null) ? (other.from != null) : !this.from.equals(other.from)) {
            return false;
        }
        if ((this.to == null) ? (other.to != null) : !this.to.equals(other.to)) {
            return false;
        }
        if ((this.command == null) ? (other.command != null) : !this.command.equals(other.command)) {
            return false;
        }
        if ((this.msgId == null) ? (other.msgId != null) : !this.msgId.equals(other.msgId)) {
            return false;
        }
        if (this.barge != other.barge && (this.barge == null || !this.barge.equals(other.barge))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 43 * hash + (this.dataTime != null ? this.dataTime.hashCode() : 0);
        hash = 43 * hash + (this.from != null ? this.from.hashCode() : 0);
        hash = 43 * hash + (this.to != null ? this.to.hashCode() : 0);
        hash = 43 * hash + (this.classification != null ? this.classification.hashCode() : 0);
        hash = 43 * hash + (this.command != null ? this.command.hashCode() : 0);
        hash = 43 * hash + (this.msgId != null ? this.msgId.hashCode() : 0);
        hash = 43 * hash + (this.barge != null ? this.barge.hashCode() : 0);
        for(int i=0; i<barge.size(); i++){
            Barge b = barge.get(i);
            System.out.println(b.toString());
        }
        return hash;
    }

    @Override
    public String toString() {
        return "TrackBroadcast{" + "dataTime=" + dataTime + ", from=" + from + ", to=" + to + ", classification=" + classification + ", command=" + command + ", msgId=" + msgId + ", barge=" + barge + '}';
    }
}

and

@XmlRootElement(name="Barge")
public class Barge {
     String misleBargeVesselId;
     String bargeName;
     String towingVesselName;
     String nonVesselName;
     String towingVesselPhoneNo;
     String towingVesselCompany;
     String positionDate;
     double latitude;
     double longitude;
     String waterwayAbbr;
     double waterwayMileMarker;
     String bargeDirection;
     String bargeCdcType;
     double bargeCdcQuantity;
     String bargeCdcMeasureUnit;
     String bargeLoadStatus;
     String nextEta;


    public String getMisleBargeVesselId() {
        return misleBargeVesselId;
    }

    @XmlAttribute(name="MISLE_Barge_Vessel_Id")
    public void setMisleBargeVesselId(String misleBargeVesselId) {
        this.misleBargeVesselId = misleBargeVesselId;
    }

    public String getBargeName() {
        return bargeName;
    }

    @XmlAttribute(name="Barge_Name")
    public void setBargeName(String bargeName) {
        this.bargeName = bargeName;
    }

    public String getTowingVesselName() {
        return towingVesselName;
    }

    @XmlAttribute(name="Towing_Vessel_Name")
    public void setTowingVesselName(String towingVesselName) {
        this.towingVesselName = towingVesselName;
    }

    public String getNonVesselName() {
        return nonVesselName;
    }

    @XmlAttribute(name="Non_Vessel_Name")
    public void setNonVesselName(String nonVesselName) {
        this.nonVesselName = nonVesselName;
    }

    public String getTowingVesselPhoneNo() {
        return towingVesselPhoneNo;
    }

    @XmlAttribute(name="Towing_Vessel_Phone_No")
    public void setTowingVesselPhoneNo(String towingVesselPhoneNo) {
        this.towingVesselPhoneNo = towingVesselPhoneNo;
    }

    public String getTowingVesselCompany() {
        return towingVesselCompany;
    }

    @XmlAttribute(name="Towing_Vessel_Company")
    public void setTowingVesselCompany(String towingVesselCompany) {
        this.towingVesselCompany = towingVesselCompany;
    }

    public String getPositionDate() {
        return positionDate;
    }

    @XmlAttribute(name="Position_Date")
    public void setPositionDate(String positionDate) {
        this.positionDate = positionDate;
    }

    public double getLatitude() {
        return latitude;
    }

    @XmlAttribute(name="Latitude")
    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    @XmlAttribute(name="Longitude")
    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public String getWaterwayAbbr() {
        return waterwayAbbr;
    }

    @XmlAttribute(name="Waterway_Abbr")
    public void setWaterwayAbbr(String waterwayAbbr) {
        this.waterwayAbbr = waterwayAbbr;
    }

    public double getWaterwayMileMarker() {
        return waterwayMileMarker;
    }

    @XmlAttribute(name="Waterway_Mile_Marker")
    public void setWaterwayMileMarker(double waerwayMileMarker) {
        this.waterwayMileMarker = waerwayMileMarker;
    }

    public String getBargeDirection() {
        return bargeDirection;
    }

    @XmlAttribute(name="Barge_Direction")
    public void setBargeDirection(String bargeDirection) {
        this.bargeDirection = bargeDirection;
    }

    public String getBargeCdcType() {
        return bargeCdcType;
    }

    @XmlAttribute(name="Barge_CDC_Type")
    public void setBargeCdcType(String bargeCdcType) {
        this.bargeCdcType = bargeCdcType;
    }

    public double getBargeCdcQuantity() {
        return bargeCdcQuantity;
    }

    @XmlAttribute(name="Barge_CDC_Quantity")
    public void setBargeCdcQuantity(double bargeCdcQuantity) {
        this.bargeCdcQuantity = bargeCdcQuantity;
    }

    public String getBargeCdcMeasureUnit() {
        return bargeCdcMeasureUnit;
    }

    @XmlAttribute(name="Barge_CDC_Measure_Unit")
    public void setBargeCdcMeasureUnit(String bargeCdcMeasureUnit) {
        this.bargeCdcMeasureUnit = bargeCdcMeasureUnit;
    }

    public String getBargeLoadStatus() {
        return bargeLoadStatus;
    }

    @XmlAttribute(name="Barge_Load_Status")
    public void setBargeLoadStatus(String bargeLoadStatus) {
        this.bargeLoadStatus = bargeLoadStatus;
    }

    public String getNextEta() {
        return nextEta;
    }

    @XmlAttribute(name="Next_ETA")
    public void setNextEta(String nextEta) {
        this.nextEta = nextEta;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Barge other = (Barge) obj;
        if ((this.misleBargeVesselId == null) ? (other.misleBargeVesselId != null) : !this.misleBargeVesselId.equals(other.misleBargeVesselId)) {
            return false;
        }
        if ((this.bargeName == null) ? (other.bargeName != null) : !this.bargeName.equals(other.bargeName)) {
            return false;
        }
        if ((this.towingVesselName == null) ? (other.towingVesselName != null) : !this.towingVesselName.equals(other.towingVesselName)) {
            return false;
        }
        if ((this.nonVesselName == null) ? (other.nonVesselName != null) : !this.nonVesselName.equals(other.nonVesselName)) {
            return false;
        }
        if ((this.towingVesselPhoneNo == null) ? (other.towingVesselPhoneNo != null) : !this.towingVesselPhoneNo.equals(other.towingVesselPhoneNo)) {
            return false;
        }
        if ((this.towingVesselCompany == null) ? (other.towingVesselCompany != null) : !this.towingVesselCompany.equals(other.towingVesselCompany)) {
            return false;
        }
        if ((this.positionDate == null) ? (other.positionDate != null) : !this.positionDate.equals(other.positionDate)) {
            return false;
        }
        if (Double.doubleToLongBits(this.latitude) != Double.doubleToLongBits(other.latitude)) {
            return false;
        }
        if (Double.doubleToLongBits(this.longitude) != Double.doubleToLongBits(other.longitude)) {
            return false;
        }
        if ((this.waterwayAbbr == null) ? (other.waterwayAbbr != null) : !this.waterwayAbbr.equals(other.waterwayAbbr)) {
            return false;
        }
        if (Double.doubleToLongBits(this.waterwayMileMarker) != Double.doubleToLongBits(other.waterwayMileMarker)) {
            return false;
        }
        if ((this.bargeDirection == null) ? (other.bargeDirection != null) : !this.bargeDirection.equals(other.bargeDirection)) {
            return false;
        }
        if ((this.bargeCdcType == null) ? (other.bargeCdcType != null) : !this.bargeCdcType.equals(other.bargeCdcType)) {
            return false;
        }
        if (Double.doubleToLongBits(this.bargeCdcQuantity) != Double.doubleToLongBits(other.bargeCdcQuantity)) {
            return false;
        }
        if ((this.bargeCdcMeasureUnit == null) ? (other.bargeCdcMeasureUnit != null) : !this.bargeCdcMeasureUnit.equals(other.bargeCdcMeasureUnit)) {
            return false;
        }
        if ((this.bargeLoadStatus == null) ? (other.bargeLoadStatus != null) : !this.bargeLoadStatus.equals(other.bargeLoadStatus)) {
            return false;
        }
        if ((this.nextEta == null) ? (other.nextEta != null) : !this.nextEta.equals(other.nextEta)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 17 * hash + (this.misleBargeVesselId != null ? this.misleBargeVesselId.hashCode() : 0);
        hash = 17 * hash + (this.bargeName != null ? this.bargeName.hashCode() : 0);
        hash = 17 * hash + (this.towingVesselName != null ? this.towingVesselName.hashCode() : 0);
        hash = 17 * hash + (this.nonVesselName != null ? this.nonVesselName.hashCode() : 0);
        hash = 17 * hash + (this.towingVesselPhoneNo != null ? this.towingVesselPhoneNo.hashCode() : 0);
        hash = 17 * hash + (this.towingVesselCompany != null ? this.towingVesselCompany.hashCode() : 0);
        hash = 17 * hash + (this.positionDate != null ? this.positionDate.hashCode() : 0);
        hash = 17 * hash + (int) (Double.doubleToLongBits(this.latitude) ^ (Double.doubleToLongBits(this.latitude) >>> 32));
        hash = 17 * hash + (int) (Double.doubleToLongBits(this.longitude) ^ (Double.doubleToLongBits(this.longitude) >>> 32));
        hash = 17 * hash + (this.waterwayAbbr != null ? this.waterwayAbbr.hashCode() : 0);
        hash = 17 * hash + (int) (Double.doubleToLongBits(this.waterwayMileMarker) ^ (Double.doubleToLongBits(this.waterwayMileMarker) >>> 32));
        hash = 17 * hash + (this.bargeDirection != null ? this.bargeDirection.hashCode() : 0);
        hash = 17 * hash + (this.bargeCdcType != null ? this.bargeCdcType.hashCode() : 0);
        hash = 17 * hash + (int) (Double.doubleToLongBits(this.bargeCdcQuantity) ^ (Double.doubleToLongBits(this.bargeCdcQuantity) >>> 32));
        hash = 17 * hash + (this.bargeCdcMeasureUnit != null ? this.bargeCdcMeasureUnit.hashCode() : 0);
        hash = 17 * hash + (this.bargeLoadStatus != null ? this.bargeLoadStatus.hashCode() : 0);
        hash = 17 * hash + (this.nextEta != null ? this.nextEta.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "Barge{" + "misleBargeVesselId=" + misleBargeVesselId + ", bargeName=" + bargeName + ", towingVesselName=" + towingVesselName + ", nonVesselName=" + nonVesselName + ", towingVesselPhoneNo=" + towingVesselPhoneNo + ", towingVesselCompany=" + towingVesselCompany + ", positionDate=" + positionDate + ", latitude=" + latitude + ", longitude=" + longitude + ", waterwayAbbr=" + waterwayAbbr + ", waerwayMileMarker=" + waterwayMileMarker + ", bargeDirection=" + bargeDirection + ", bargeCdcType=" + bargeCdcType + ", bargeCdcQuantity=" + bargeCdcQuantity + ", bargeCdcMeasureUnit=" + bargeCdcMeasureUnit + ", bargeLoadStatus=" + bargeLoadStatus + ", nextEta=" + nextEta + '}';
    }
}

When I unmarshall the file I can get everything in the TrackBroadcast except for the Barges. I’m new to JAXB and was wondering if anyone could see what I might be doing wrong or if anyone could nudge me in the right direction.

  • 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-01T10:21:59+00:00Added an answer on June 1, 2026 at 10:21 am

    You should just need to add @XmlElement(name="Barge") as by the JAXB (JSR-222) default naming rules JAXB implementations will look for elements with the name barge instead of Barge:

    @XmlElement(name="Barge")
    public List<Barge> getBarge() {
        return barge;
    }
    

    For More Information

    • http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on an assignment that has me creating a Map class in
I'm working on creating a command line game in Java. The basic premise that
I had a problem working with the image classes in java. I am creating
I am working on creating a web app that will query event logs on
So I'm working on creating a visualization for a data structure in Java. I
I'm working through a JPanel exercise in a Java book. I'm tasked with creating
I'm creating an Android application (Android 2.3.3) that has a header, a footer and
So I have been working on a 2 player Tic-Tac-Toe game in java that
I was working with java code that is supposedly using the Factory pattern, but
I tried to make a file choose following the below link http://www.dreamincode.net/forums/topic/190013-creating-simple-file-chooser/ However, 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.