- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个 Java 类来映射具有多个相同元素的 XML 文件。以下 XML 是该文件的示例:
<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>
我的 JAXB 类可以读入 DateTime、From、To、Classification、Command 和 MsgId 元素,但无法读入 Barge 元素。我有两个类试图封装 XML,但我知道我做错了什么。这两个类是:
@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 + '}';
}
}
和
@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 + '}';
}
}
当我解码文件时,我可以获得 TrackBroadcast 中的所有内容,但 Barges 除外。我是 JAXB 的新手,想知道是否有人可以看到我可能做错了什么,或者是否有人可以将我推向正确的方向。
最佳答案
你应该只需要添加 @XmlElement(name="Barge")
作为 JAXB (JSR-222)默认命名规则 JAXB 实现将查找名称为 barge
而不是 Barge
的元素:
@XmlElement(name="Barge")
public List<Barge> getBarge() {
return barge;
}
了解更多信息
关于java - 将 JAXB 与包含许多相同元素的 XML 文件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10029228/
我有一个类似于以下的结构。 class A { string title; List bItem; } class B { int pric
本地流 和 远程流 两者都是“媒体流列表 ”。 本地流 包含“本地媒体流 ” 对象 但是,远程流 包含“媒体流 ” 对象 为什么差别这么大? 当我使用“本地流 “- 这个对我有用: localVide
我正在尝试将 8 列虚拟变量转换为 8 级排名的一列。 我试图用这个公式来做到这一点: =IF(OR(A1="1");"1";IF(OR(B1="1");"2";IF(OR(C1="1");"3";I
我正在使用面向对象编程在 Python 中创建一个有点复杂的棋盘游戏的实现。 我的问题是,许多这些对象应该能够与其他对象交互,即使它们不包含在其中。 例如Game是一个对象,其中包含PointTrac
有没有办法获取与 contains 语句匹配的最深元素? 基本上,如果我有嵌套的 div,我想要最后一个元素而不是父元素: Needle $("div:contains('Needle')")
出于某种原因,我无法在 Google 上找到答案!但是使用 SQL contains 函数我怎么能告诉它从字符串的开头开始,即我正在寻找等同于的全文 喜欢 'some_term%'。 我知道我可以使用
我正在尝试创建一个正则表达式来匹配具有 3 个或更多元音的字符串。 我试过这个: [aeiou]{3,} 但它仅在元音按顺序排列时才有效。有什么建议吗? 例如: 塞缪尔 -> 有效 琼 -> 无效 S
嘿所以我遇到了这样的情况,我从数据库中拉回一个客户,并通过包含的方式包含所有案例研究 return (from c in db.Clients.Include("CaseStudies")
如果关键字是子字符串,我无法弄清楚为什么这个函数不返回结果。 const string = 'cake'; const substring = 'cak'; console.log(string.in
我正在尝试将包含特定文本字符串的任何元素更改为红色。在我的示例中,我可以将子元素变为蓝色,但是我编写“替换我”行的方式有些不正确;红色不会发生变化。我注意到“contains”方法通常写为 :cont
我想问一下我是否可以要求/包含一个语法错误的文件,如果不能,则require/include返回一个值,这样我就知道所需/包含的文件存在语法错误并且不能被要求/包含? file.php语法错误 inc
我想为所有包含youtube链接的链接添加一个rel。 这就是我正在使用的东西-但它没有用。有任何想法吗? $('a [href:contains(“youtube.com”)]')。attr('re
我正在尝试在 Elasticsearch 中查询。除搜索中出现“/”外,此功能均正常运行。查询如下所示 GET styling_rules/product_line_filters/_search {
我正在开发名为eBookRepository的ASP.NET MVC应用程序,其中包含在线图书。 电子书具有自己的标题,作者等。因此,现在我正在尝试实现搜索机制。我必须使用Elasticsearch作
我已阅读Firebase Documentation并且不明白什么是 .contains()。 以下是文档中 Firebase 数据库的示例规则: { "rules": { "rooms"
我的问题是我可以给出条件[ 'BookTitleMaster.id' => $xtitid, ] 如下所示 $bbookinfs = $this->BookStockin->BookIssue->fi
我需要能够使用 | 检查模式在他们中。例如,对于像“dtest|test”这样的字符串,像 d*|*t 这样的表达式应该返回 true。 我不是正则表达式英雄,所以我只是尝试了一些事情,例如: Reg
我想创建一个正则表达式来不匹配某些单词... 我的字符:var test = "é123rr;and;ià456;or;456543" 我的正则表达式:test.match(\((?!and)(?!o
我在 XSLT 中有一个名为 variable_name 的变量,如果相关产品具有名称为 A 或 B 或两者均为 A & 的属性,我将尝试将其设置为 1 B.
您好,我想让接待员和经理能够查看工作类型和费率并随后进行更新。但是技术人员只能查看不能更新。该图是否有效? 我读到扩展用例是由发起基本用例的参与者发起的。我应该如何区分技术人员只能启动基本案例而不能启
我是一名优秀的程序员,十分优秀!