あなたは、xmlエディタがxsdスキームからサンプルXMLを作成し、すべての要素と属性をランダムなもので埋め込む方法を知っています。今私は空のルート要素タグを取得します。 JAXBを使用してxmlをマーシャリングすることが可能であり、テストの理由で同様のことを達成できますか? 私はjavaとjaxbの初心者ですが、どんな助けもありがとうございます。JAXB - サンプルxmlを生成しますか?
EDIT。ルート要素クラスの コード:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"document",
"taskList",
"addDocuments",
"expansion",
"acknowledgement"
})
@XmlRootElement(name = "Header")
public class Header {
@XmlElement(name = "Document")
protected DocumentType document;
@XmlElement(name = "TaskList")
protected TaskListType taskList;
@XmlElement(name = "AddDocuments")
protected AddDocumentsType addDocuments;
@XmlElement(name = "Expansion")
protected ExpansionType expansion;
@XmlElement(name = "Acknowledgement")
protected AcknowledgementType acknowledgement;
@XmlAttribute(name = "time", required = true)
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar time;
@XmlAttribute(name = "msg_type", required = true)
protected short msgType;
@XmlAttribute(name = "msg_id", required = true)
protected String msgId;
@XmlAttribute(name = "msg_acknow")
protected Short msgAcknow;
@XmlAttribute(name = "from_org_id", required = true)
protected String fromOrgId;
@XmlAttribute(name = "from_organization", required = true)
protected String fromOrganization;
@XmlAttribute(name = "from_department")
protected String fromDepartment;
@XmlAttribute(name = "from_sys_id", required = true)
protected String fromSysId;
@XmlAttribute(name = "from_system", required = true)
protected String fromSystem;
@XmlAttribute(name = "from_system_details")
protected String fromSystemDetails;
@XmlAttribute(name = "to_org_id")
protected String toOrgId;
@XmlAttribute(name = "to_organization", required = true)
protected String toOrganization;
@XmlAttribute(name = "to_department")
protected String toDepartment;
@XmlAttribute(name = "to_sys_id")
protected String toSysId;
@XmlAttribute(name = "to_system")
protected String toSystem;
@XmlAttribute(name = "to_system_details")
protected String toSystemDetails;
// getters n setters are omitted
}
XMLを作成:
ObjectFactory objectFactory = new ObjectFactory();
Header header = objectFactory.createHeader();
JAXBContext jaxbContext = JAXBContext.newInstance(Header.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(header, file);
私は何を得る:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Header msg_type="0" />
他のすべてがですか?すべての要素や属性を作成せずに値を手動で設定せずに、完全なxmlに似たものを受け取ることはできますか?
達成しようとしていることは100%わかりません。 JAXBアノテートクラスをテストデータ付きのXMLにレンダリングしますか? –
今、私は空のルート要素タグを取得します。すべてのネストされた要素と属性にいくつかのテストデータを設定します。 – bunnyjesse112
JAXBアノテーション付きBeanからschemagenを使用してXSDを生成し、このXSDからサンプルXMLを生成するようXMLエディタに依頼します。 –