XJC生成的JAXB类的XSD变量过多

时间:2019-01-11 14:24:50

标签: xml xslt xsd jaxb xjc

我下面有一些非常基本的数据。我正在使用的工作流程是将Google表格中的数据作为单列数据导出到xml

如何使用JAXBtrang之类的工具或下面的xmllint之类的工具生成合理的xjc类?

thufir@dur:~/jaxb$ 
thufir@dur:~/jaxb$ cat dummy.xml 
<data>
  <b />
  <c />
  <d />
  <e />
  <f />
  <f />
  <h />
  <i />
</data>

thufir@dur:~/jaxb$ 
thufir@dur:~/jaxb$ trang dummy.xml dummy.xsd
thufir@dur:~/jaxb$ 
thufir@dur:~/jaxb$ cat dummy.xsd 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="data">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="b"/>
        <xs:element ref="c"/>
        <xs:element ref="d"/>
        <xs:element ref="e"/>
        <xs:element maxOccurs="unbounded" ref="f"/>
        <xs:element ref="h"/>
        <xs:element ref="i"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="b">
    <xs:complexType/>
  </xs:element>
  <xs:element name="c">
    <xs:complexType/>
  </xs:element>
  <xs:element name="d">
    <xs:complexType/>
  </xs:element>
  <xs:element name="e">
    <xs:complexType/>
  </xs:element>
  <xs:element name="f">
    <xs:complexType/>
  </xs:element>
  <xs:element name="h">
    <xs:complexType/>
  </xs:element>
  <xs:element name="i">
    <xs:complexType/>
  </xs:element>
</xs:schema>
thufir@dur:~/jaxb$ 

我可以将jaxb文件创建为:

thufir@dur:~/jaxb$ 
thufir@dur:~/jaxb$ xjc dummy.xsd 
parsing a schema...
compiling a schema...
generated/B.java
generated/C.java
generated/D.java
generated/Data.java
generated/E.java
generated/F.java
generated/H.java
generated/I.java
generated/ObjectFactory.java
thufir@dur:~/jaxb$ 
thufir@dur:~/jaxb$ wc -l generated/Data.java 
246 generated/Data.java
thufir@dur:~/jaxb$ 
thufir@dur:~/jaxb$ head generated/Data.java -n 77
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2019.01.11 at 06:17:29 AM PST 
//


package generated;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element ref="{}b"/>
 *         &lt;element ref="{}c"/>
 *         &lt;element ref="{}d"/>
 *         &lt;element ref="{}e"/>
 *         &lt;element ref="{}f" maxOccurs="unbounded"/>
 *         &lt;element ref="{}h"/>
 *         &lt;element ref="{}i"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "b",
    "c",
    "d",
    "e",
    "f",
    "h",
    "i"
})
@XmlRootElement(name = "data")
public class Data {

    @XmlElement(required = true)
    protected B b;
    @XmlElement(required = true)
    protected C c;
    @XmlElement(required = true)
    protected D d;
    @XmlElement(required = true)
    protected E e;
    @XmlElement(required = true)
    protected List<F> f;
    @XmlElement(required = true)
    protected H h;
    @XmlElement(required = true)
    protected I i;

    /**
     * Gets the value of the b property.
     * 
     * @return
     *     possible object is
thufir@dur:~/jaxb$ 

首先,有点垃圾邮件。

每个元素是否具有必须一个不同的方法?这是一个简单的CSV文件,但是到达Java时非常复杂。

什么是更理智的方法?因为如果原始文件只有一千行,那么我不禁思索生成的Java类是什么样子。

那么,如何修复xsd文件?

0 个答案:

没有答案