我正在尝试重新读取由我的 Java 程序生成的 XML 文件,并以表格的JTable
形式提供它的图形表示。手动生成的 XML 符合架构,但程序将其检测为无效。
逻辑很简单:
1. 检查task-list.xml
and是否task-list-schema.xsd
存在。
2. 如果是,解组 XML,使用 XML 文档中的数据准备行,将行添加到表中。
3.如果没有,准备一个空白的GUI。
问题是 XML 不符合模式。问题不在于生成的 XML 或用于绑定的类中的模式。它们是这样的:
FormatList
|->Vector<Format>
TaskList
|-> Vector<Task>
Task
|-> input xs:string
|-> output xs:string
|-> Format
|-> taskID xs:integer
|-> isReady xs:boolean
Format
|-> name xs:string
|-> width xs:string
|-> height xs:string
|-> extension xs:string
因此,FormatList
两者Task
共享同一个类Format
,因为每个视频转换任务都有与之关联的格式。
这是我得到的错误:
这是生成的 XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<task-list>
<task>
<input>E:\Videos\AutoIT\AutoIt Coding Tutorial Two - Website Functions.flv</input>
<output>E:\test\StandaloneVideoConverter</output>
<format>
<name>[AVI] HD 1080p</name>
<width>1920</width>
<height>1080</height>
<extension>.avi</extension>
</format>
<taskID>3</taskID>
<isReady>false</isReady>
</task>
</task-list>
我该如何解决这个问题?
课程
@XmlAccessorType(XmlAccessType.FIELD)
public class Format {
@XmlElement(name="name")
private String name;
@XmlElement(name="width")
private int width;
@XmlElement(name="height")
private int height;
@XmlElement(name="extension")
private String extension;
//getters and setters, synchronized
}
@XmlRootElement(name="format-list")
@XmlAccessorType(XmlAccessType.FIELD)
public class FormatList {
@XmlElement(name="format")
private Vector<Format> formats;
public Vector<Format> getFormats(){
return formats;
}
// this is the complete class
}
@XmlAccessorType(XmlAccessType.FIELD)
public class Task {
@XmlElement(name="input")
private String input; // String representing the input file
@XmlElement(name="output")
private String output; // String representing the output file
@XmlElement(name="format")
private Format format; // a jaxb.classes.Format representing the format of conversion
@XmlElement(name="taskID")
private long taskID; // a unique ID for each task.
@XmlElement(name="isReady")
private boolean isReady; // boolean value representing whether the task is ready for conversion
@XmlTransient
private boolean isChanging = false; // boolean representing if the user is changing the task DO NOT MARSHALL
@XmlTransient
private boolean isExecuting = false; // boolean representing whether the task is being executed DO NOT MARSHALL
// getters and setters, synchronized
}
@XmlRootElement(name="task-list")
@XmlAccessorType(XmlAccessType.FIELD)
public class TaskList {
public TaskList(){
tasks = new Vector<Task>();
}
@XmlElement(name="task")
Vector<Task> tasks;
public Vector<Task> getTasks(){
return tasks;
}
// this is the complete class
}