【发布时间】:2014-07-14 06:55:38
【问题描述】:
我正在使用 JAXB 将 Java 对象编组为 XML。我正在使用的 ide 是 Windows 操作系统中的 JDeveloper 11.1.1.7.0。每当我运行那个特定的 java 代码时,我都会收到一条错误消息,上面写着
"Error(1,1): file:/C:/JDeveloper/mywork/bugdashboard/Model/src/model/BugReport.xml<Line 1, Column 1>: XML-20108: (Fatal Error) Start of root element expected."
即使代码中似乎没有错误,我仍然无法获得所需的输出..请帮助..
我的 JAVA 代码..
package model;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
public class JavaObvjecttoXml {
public void xmlGenerator() {
//super();
JavaServiceFacade fcd = new JavaServiceFacade();
bugvalue track, track1, track2;
List<ReportDto> bugReport, bugrePort1, bugrePort2;
List<bugvalue> reportMetaData= new ArrayList<bugvalue>();
ReportMetaData rmd = new ReportMetaData();
try {
rmd.setBugreportmetadata(new ArrayList<bugvalue> ());
JAXBContext context = JAXBContext.newInstance(ReportMetaData.class);
Marshaller marshaller;
marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
track = new bugvalue();
bugReport = fcd.getBugSeverityReport();
track.setBugReport(bugReport);
track.setLabel("Bug by severity");
track.setTile("severity");
track.setChatType("PIE");
track.setXAxisLabel("Label");
track.setYAxisLAbel("Label Count");
track1 = new bugvalue();
bugrePort1 = fcd.getBugStatusReport();
track1.setBugReport(bugrePort1);
track1.setLabel("Bug by Status");
track1.setTile("status");
track1.setChatType("bar");
track1.setXAxisLabel("count");
track1.setYAxisLAbel("Label");
track2 = new bugvalue();
bugrePort2 = fcd.getBugCategoryReport();
track2.setBugReport(bugrePort2);
track2.setLabel("Bug by Category");
track2.setTile("category");
track2.setChatType("PIE");
track2.setXAxisLabel("count");
track2.setYAxisLAbel("Label");
reportMetaData.add(track);
reportMetaData.add(track1);
reportMetaData.add(track2);
rmd.setBugreportmetadata(reportMetaData);
File output = new File("C:\\JDeveloper\\mywork\\bugdashboard\\Model\\src\\model\\BugReport.xml");
marshaller.marshal(rmd, output);
}
catch(JAXBException e){
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
JavaObvjecttoXml obj = new JavaObvjecttoXml();
obj.xmlGenerator();
}
}
文件 ReportMetaData.java
package model;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@ XmlRootElement(name = "ReportMetaData")
public class ReportMetaData {
private List<bugvalue> bugreportmetadata = new ArrayList<bugvalue>();
public List<bugvalue> getBugreportmetadata() {
return bugreportmetadata;
}
*/ @param bugreportmetadata
*/
public void setBugreportmetadata(List<bugvalue> bugreportmetadata) {
this.bugreportmetadata = bugreportmetadata;
}
public ReportMetaData() {
super();
}
}
错误信息..
文件 BugReport.xml
从上面的屏幕截图可以看出,正在生成文件 BugReport.xml,但它是空的..
【问题讨论】:
-
请发布您的课程
ReportMetaData。 -
@AlexR 我已经添加了类 ReportMetaData..
-
我对您的错误消息感到困惑。请发送您生成的文件
BugReport.xml -
xml 文件为空..我已附上屏幕截图...正在生成但它是空的..
-
@BlaisDoughan 你能看看这个问题吗?
标签: java xml jaxb marshalling