我已经阅读了几个JAXB教程,并尝试实现自己的教程。我回来了。我不确定为什么我会变空。 这是我的XML文档。我很抱歉这篇文章的主要代码有多长。我只是不确定我是否正确实现JAXB。
<EZMAXMOBILE_OFFLINE_PROPERTIES synctime="">
<ENTITY_DEFS>
<ENTITY name="WORKORDER">
<INDEXES>
<INDEX name="IDX_WO_1">WORKORDERID</INDEX>
<INDEX name="IDX_WO_2">WONUM, SITEID</INDEX>
<INDEX name="IDX_WO_3">ASSETNUM, SITEID</INDEX>
<INDEX name="IDX_WO_4">LOCATION, SITEID</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN autokey="Y" autokeyprefix="LOCAL" parentkeycol="PARENTID" uniquekey="Y">WORKORDERID</COLUMN>
<COLUMN displaykey="Y" autokey="Y" autokeyprefix="OFFLN">WONUM</COLUMN>
<COLUMN>PARENTID</COLUMN>
<COLUMN>PARENT</COLUMN>
<COLUMN>DESCRIPTION</COLUMN>
<COLUMN>LONGDESCRIPTION</COLUMN>
<COLUMN>LOCATION</COLUMN>
<COLUMN>ASSETNUM</COLUMN>
<COLUMN>PERSONGROUP</COLUMN>
<COLUMN>CREWID</COLUMN>
<COLUMN>SUPERVISOR</COLUMN>
<COLUMN>LEAD</COLUMN>
<COLUMN>PHONE</COLUMN>
<COLUMN>REPORTEDBY</COLUMN>
<COLUMN>REPORTDATE</COLUMN>
<COLUMN>STATUS</COLUMN>
<COLUMN>STATUSDATE</COLUMN>
<COLUMN>WOPRIORITY</COLUMN>
<COLUMN>WORKTYPE</COLUMN>
<COLUMN>FAILURECODE</COLUMN>
<COLUMN>PROBLEMCODE</COLUMN>
<COLUMN>ISTASK</COLUMN>
<COLUMN>ORIGRECORDID</COLUMN>
<COLUMN>ESTDUR</COLUMN>
<COLUMN>OBSERVATION</COLUMN>
<COLUMN>MEASUREMENTVALUE</COLUMN>
<COLUMN>TASKID</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>ORGID</COLUMN>
</COLUMNS>
<INIT_ACTION>
<ACTION>offline/getMyWorkOrderListJson.action</ACTION>
<ACTION>offline/getMyTaskWorkOrderListJson.action</ACTION>
</INIT_ACTION>
<DELTA_ACTION>
<ACTION>offline/getDeltaMyWorkOrderListJson.action</ACTION>
<ACTION>offline/getDeltaMyTaskWorkOrderListJson.action</ACTION>
</DELTA_ACTION>
<SYNC_ACTIONS transentityname="WORKORDER" transentitykey="WORKORDERID">
<ACTION name="INSERT" beanname="OfflineDataSyncAction" methodname="addWorkOrder"/>
<ACTION name="EDIT" beanname="OfflineDataSyncAction" methodname="editWorkOrder"/>
<ACTION name="INSERT_TASK" beanname="OfflineDataSyncAction" methodname="addTaskWorkOrder"/>
<ACTION name="UPDATE_STATUS" beanname="OfflineDataSyncAction" methodname="updateWorkOrderStatus"/>
<ACTION name="UPDATE_TASK" beanname="OfflineDataSyncAction" methodname="updateWorkOrderTask"/>
<ACTION name="UPDATE_TASK_STATUS" beanname="OfflineDataSyncAction" methodname="updateWorkOrderStatus"/>
<ACTION name="EMM_FILE_UPLOAD"/>
</SYNC_ACTIONS>
</ENTITY>
<ENTITY name="LABTRANS">
<INDEXES>
<INDEX name="IDX_LT_1">WONUM, SITEID, LABORCODE</INDEX>
<INDEX name="IDX_LT_2">WONUM, SITEID, LABORCODE, TIMERSTATUS</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN displaykey="Y" uniquekey="Y" autokey="Y" autokeyprefix="LT">LABTRANSID</COLUMN>
<COLUMN>WORKORDERID</COLUMN>
<COLUMN>WONUM</COLUMN>
<COLUMN>LABORCODE</COLUMN>
<COLUMN>CRAFT</COLUMN>
<COLUMN>REGULARHRS</COLUMN>
<COLUMN>PREMIUMPAYCODE</COLUMN>
<COLUMN>PREMIUMPAYHOURS</COLUMN>
<COLUMN>STARTDATE</COLUMN>
<COLUMN>FINISHDATE</COLUMN>
<COLUMN>TRANSTYPE</COLUMN>
<COLUMN>TIMERSTATUS</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>ORGID</COLUMN>
</COLUMNS>
<INIT_ACTION>
<ACTION>offline/getMyLabTransJson.action</ACTION>
<ACTION>offline/getMyTaskLabTransJson.action</ACTION>
</INIT_ACTION>
<DELTA_ACTION>
<ACTION>offline/getDeltaMyLabTransJson.action</ACTION>
<ACTION>offline/getDeltaMyTaskLabTransJson.action</ACTION>
</DELTA_ACTION>
<SYNC_ACTIONS transentityname="WORKORDER" transentitykey="WORKORDERID">
<ACTION name="INSERT" beanname="OfflineDataSyncAction" methodname="addLabTrans"/>
<ACTION name="START_TIMER" beanname="OfflineDataSyncAction" methodname="startTimer"/>
<ACTION name="STOP_TIMER" beanname="OfflineDataSyncAction" methodname="stopTimer"/>
</SYNC_ACTIONS>
</ENTITY>
<ENTITY name="MATUSETRANS">
<INDEXES>
<INDEX name="IDX_MT_1">WONUM, SITEID</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN displaykey="Y" uniquekey="Y">MATUSETRANSID</COLUMN>
<COLUMN>WORKORDERID</COLUMN>
<COLUMN>WONUM</COLUMN>
<COLUMN>DESCRIPTION</COLUMN>
<COLUMN>LINETYPE</COLUMN>
<COLUMN>ITEMNUM</COLUMN>
<COLUMN>QUANTITY</COLUMN>
<COLUMN>UNITCOST</COLUMN>
<COLUMN>TRANSDATE</COLUMN>
<COLUMN>ISSUETYPE</COLUMN>
<COLUMN>ISSUETO</COLUMN>
<COLUMN>BINNUM</COLUMN>
<COLUMN>LOTNUM</COLUMN>
<COLUMN>STORELOC</COLUMN>
<COLUMN>ASSETNUM</COLUMN>
<COLUMN>LOCATION</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>ORGID</COLUMN>
</COLUMNS>
<INIT_ACTION>offline/getMyMatUseTransJson.action</INIT_ACTION>
<DELTA_ACTION>offline/getDeltaMyMatUseTransJson.action</DELTA_ACTION>
<SYNC_ACTIONS transentityname="WORKORDER" transentitykey="WORKORDERID">
<ACTION name="INSERT" beanname="OfflineDataSyncAction" methodname="addMatUseTrans"/>
</SYNC_ACTIONS>
</ENTITY>
<ENTITY name="WORKLOG">
<INDEXES>
<INDEX name="IDX_WL_1">WONUM, SITEID</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN displaykey="Y" uniquekey="Y">WORKLOGID</COLUMN>
<COLUMN>WONUM</COLUMN>
<COLUMN>WORKORDERID</COLUMN>
<COLUMN>RECORDKEY</COLUMN>
<COLUMN>DESCRIPTION</COLUMN>
<COLUMN>LONGDESCRIPTION</COLUMN>
<COLUMN>CLASS</COLUMN>
<COLUMN>CREATEBY</COLUMN>
<COLUMN>CREATEDATE</COLUMN>
<COLUMN>LOGTYPE</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>ORGID</COLUMN>
</COLUMNS>
<INIT_ACTION>offline/getMyWorkLogListJson.action</INIT_ACTION>
<DELTA_ACTION>offline/getDeltaMyWorkLogListJson.action</DELTA_ACTION>
<SYNC_ACTIONS transentityname="WORKORDER" transentitykey="WORKORDERID">
<ACTION name="INSERT" beanname="OfflineDataSyncAction" methodname="addWorkLog"/>
</SYNC_ACTIONS>
</ENTITY>
<ENTITY name="FAILUREREPORT">
<INDEXES>
<INDEX name="IDX_FR_1">WORKORDERID</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN uniquekey="Y">WORKORDERID</COLUMN>
<COLUMN displaykey="Y" >WONUM</COLUMN>
<COLUMN>FAILURECODE</COLUMN>
<COLUMN>PROBLEMCODE</COLUMN>
<COLUMN>CAUSECODE</COLUMN>
<COLUMN>REMEDYCODE</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>ORGID</COLUMN>
</COLUMNS>
<INIT_ACTION>offline/getMyFailureRptListJson.action</INIT_ACTION>
<DELTA_ACTION>offline/getDeltaMyFailureRptListJson.action</DELTA_ACTION>
<SYNC_ACTIONS transentityname="WORKORDER" transentitykey="WORKORDERID">
<ACTION name="EDIT" beanname="OfflineDataSyncAction" methodname="editFailureReport"/>
</SYNC_ACTIONS>
</ENTITY>
<ENTITY name="MULTIASSETLOCCI">
<INDEXES>
<INDEX name="IDX_MULTI_1">WORKORDERID</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN displaykey="Y" uniquekey="Y">MULTIID</COLUMN>
<COLUMN>SEQUENCE</COLUMN>
<COLUMN>RECORDKEY</COLUMN>
<COLUMN>WORKORDERID</COLUMN>
<COLUMN>ASSETNUM</COLUMN>
<COLUMN>LOCATION</COLUMN>
<COLUMN>ROUTE</COLUMN>
<COLUMN>ROUTESTOP</COLUMN>
<COLUMN>TARGETDESC</COLUMN>
<COLUMN>COMMENTS</COLUMN>
<COLUMN>PROGRESS</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>ORGID</COLUMN>
</COLUMNS>
<INIT_ACTION>offline/getMyMultiAssetLocListJson.action</INIT_ACTION>
<DELTA_ACTION>offline/getDeltaMyMultiAssetLocListJson.action</DELTA_ACTION>
<SYNC_ACTIONS transentityname="WORKORDER" transentitykey="WORKORDERID">
<ACTION name="EDIT_PRG" beanname="OfflineDataSyncAction" methodname="editMultiProgress"/>
</SYNC_ACTIONS>
</ENTITY>
<ENTITY name="INVENTORY">
<INDEXES>
<INDEX name="IDX_INV_1">ITEMNUM, SITEID</INDEX>
<INDEX name="IDX_INV_2">ITEMNUM</INDEX>
<INDEX name="IDX_INV_3">ITEMNUM, LOCATION</INDEX>
<INDEX name="IDX_INV_4">SITEID</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN displaykey="Y" uniquekey="Y">INVENTORYID</COLUMN>
<COLUMN>ITEMNUM</COLUMN>
<COLUMN>ITEMSETID</COLUMN>
<COLUMN>LOCATION</COLUMN>
<COLUMN>DESCRIPTION</COLUMN>
<COLUMN>CATEGORY</COLUMN>
<COLUMN>MANUFACTURER</COLUMN>
<COLUMN>MODELNUM</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>STATUS</COLUMN>
<COLUMN>STATUSDATE</COLUMN>
<COLUMN>BINNUM</COLUMN>
<COLUMN>ISSUEUNIT</COLUMN>
<COLUMN>ISSUEYTD</COLUMN>
<COLUMN>ISSUE1YRAGO</COLUMN>
<COLUMN>LASTISSUEDATE</COLUMN>
</COLUMNS>
<INIT_ACTION>offline/getAllInventoryJson.action</INIT_ACTION>
<DELTA_ACTION>offline/getDeltaInventoryListJson.action</DELTA_ACTION>
<SYNC_ACTIONS transentityname="INVENTORY" transentitykey="INVENTORYID">
<ACTION name="UPDATE_STATUS" beanname="OfflineDataSyncAction" methodname="updateInventoryStatus"/>
</SYNC_ACTIONS>
</ENTITY>
<ENTITY name="INVBALANCES">
<INDEXES>
<INDEX name="IDX_INVBAL_1">ITEMNUM, SITEID</INDEX>
<INDEX name="IDX_INVBAL_2">ITEMNUM</INDEX>
<INDEX name="IDX_INVBAL_3">ITEMNUM, LOCATION</INDEX>
<INDEX name="IDX_INVBAL_4">SITEID</INDEX>
<INDEX name="IDX_INVBAL_5">BINNUM</INDEX>
</INDEXES>
<COLUMNS>
<COLUMN uniquekey="Y">INVBALANCESID</COLUMN>
<COLUMN displaykey="Y">ITEMNUM</COLUMN>
<COLUMN>ITEMSETID</COLUMN>
<COLUMN>LOCATION</COLUMN>
<COLUMN>DESCRIPTION</COLUMN>
<COLUMN>LOTTYPE</COLUMN>
<COLUMN>ITEMTYPE</COLUMN>
<COLUMN>STATUS</COLUMN>
<COLUMN>BINNUM</COLUMN>
<COLUMN>LOTNUM</COLUMN>
<COLUMN>CURBAL</COLUMN>
<COLUMN>PHYSCNT</COLUMN>
<COLUMN>PHYSCNTDATE</COLUMN>
<COLUMN>RECONCILED</COLUMN>
<COLUMN>SITEID</COLUMN>
<COLUMN>ORGID</COLUMN>
</COLUMNS>
<INIT_ACTION>offline/getInvBalancesJson.action</INIT_ACTION>
<DELTA_ACTION>offline/getDeltaInvBalancesJson.action</DELTA_ACTION>
<SYNC_ACTIONS transentityname="INVBALANCES" transentitykey="INVBALANCESID">
<ACTION name="UPDATE_PHYSCNT" beanname="OfflineDataSyncAction" methodname="adjustPhysicalCount"/>
</SYNC_ACTIONS>
</ENTITY>
</ENTITY_DEFS>
</EZMAXMOBILE_OFFLINE_PROPERTIES>
这是我的运行类来解组我的xml。
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import com.interpro.Objects.*;
public class run {
/**
* @param args
*/
public static void main(String[] args) {
try {
File file = new File("C:/Development/workspace/com.interpro.xml/src/XML/offlineconfig.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(EZMAXMOBILE_OFFLINE_PROPERTIES.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
EZMAXMOBILE_OFFLINE_PROPERTIES emm = (EZMAXMOBILE_OFFLINE_PROPERTIES) jaxbUnmarshaller.unmarshal(file);
System.out.println();
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
以下是我生成的一些课程。
package com.interpro.Objects;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "EZMAXMOBILE_OFFLINE_PROPERTIES")
@XmlType(propOrder = {"entity_defs", "selection_defs", "tx_settings", "offline_file_cache"})
public class EZMAXMOBILE_OFFLINE_PROPERTIES {
private String synctime;
private ENTITY_DEFS entity_defs;
public ENTITY_DEFS getEntity_defs() {
return entity_defs;
}
@XmlElement
public void setEntity_defs(ENTITY_DEFS entity_defs) {
this.entity_defs = entity_defs;
}
public SELECTION_DEFS getSelection_defs() {
return selection_defs;
}
@XmlElement
public void setSelection_defs(SELECTION_DEFS selection_defs) {
this.selection_defs = selection_defs;
}
public TX_SETTINGS getTx_settings() {
return tx_settings;
}
@XmlElement
public void setTx_settings(TX_SETTINGS tx_settings) {
this.tx_settings = tx_settings;
}
public OFFLINE_FILE_CACHE getOffline_file_cache() {
return offline_file_cache;
}
@XmlElement
public void setOffline_file_cache(OFFLINE_FILE_CACHE offline_file_cache) {
this.offline_file_cache = offline_file_cache;
}
private SELECTION_DEFS selection_defs;
private TX_SETTINGS tx_settings;
private OFFLINE_FILE_CACHE offline_file_cache;
public String getSynctime() {
return synctime;
}
@XmlAttribute
public void setSynctime(String synctime) {
this.synctime = synctime;
}
} EZMAXMOBILE_OFFLINE_PROPERTIES类应生成Entity_defs对象
package com.interpro.Objects;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
public class ENTITY_DEFS {
private ArrayList<ENTITY> entitylist;
public ArrayList<ENTITY> getEntitylist() {
return entitylist;
}
@XmlElement
public void setEntitylist(ArrayList<ENTITY> entitylist) {
this.entitylist = entitylist;
}
} 然后在ENTITY_DEFS内部,它应该列出ENTITY对象。
package com.interpro.Objects;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
public class ENTITY {
private String name;
public String getName() {
return name;
}@XmlAttribute
public void setName(String name) {
this.name = name;
}
private INDEXES indexes;
public INDEXES getIndexes() {
return indexes;
}@XmlElement
public void setIndexes(INDEXES indexes) {
this.indexes = indexes;
}
public COLUMNS getColumns() {
return columns;
}@XmlElement
public void setColumns(COLUMNS columns) {
this.columns = columns;
}
public INIT_ACTION getInit_action() {
return init_action;
}@XmlElement
public void setInit_action(INIT_ACTION init_action) {
this.init_action = init_action;
}
public DELTA_ACTION getDelta_action() {
return delta_action;
}@XmlElement
public void setDelta_action(DELTA_ACTION delta_action) {
this.delta_action = delta_action;
}
public SYNC_ACTION getSync_action() {
return sync_action;
}@XmlElement
public void setSync_action(SYNC_ACTION sync_action) {
this.sync_action = sync_action;
}
private COLUMNS columns;
private INIT_ACTION init_action;
private DELTA_ACTION delta_action;
private SYNC_ACTION sync_action;
}
答案 0 :(得分:1)
您可以填充对象模型,然后编组它以了解JAXB当前期望的XML输入。快速浏览一下您的模型,您至少需要以下内容:
@XmlElement
注释指定要映射到的元素名称,因为基于您的字段/属性的默认名称不匹配。@XmlElementWrapper
注释。