如何在JAXB生成为列表的元素上添加xsi:nil =“ true”?

时间:2019-10-10 08:26:05

标签: java xsd jaxb xml-nil

我有一些XSD的一部分:

1。

<element name="element1" type="complexType" nillable="true" minOccurs="0" maxOccurs="unbounded"/>

2。

<complexType name="complexType">
        <complexContent>
            <restriction base="someOtherComplexType">
                <sequence>
                        <SOME_ELEMENTS_HERE>
                </sequence>
                <attribute ref="ns:someAttribute1" use="required" fixed="ABC"/>
                <attribute ref="ns:someAttribute2" use="required"/>
            </restriction>
        </complexContent>
    </complexType>

element1以Java代码的列表形式生成。当我将元素添加到列表中时,JAXB的序列化如下:

<ns:element1 ns:someAttribute="ABC" ns:someAttribute2="T"/>

但是,这与模式无关,因为它缺少“序列”部分中的数据。 由于我不想为“序列”添加任何内容,因此需要生成以下输出以便符合XSD:

<ns:element1 ns:someAttribute="ABC" ns:someAttribute2="T" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

您是否知道如何执行这些操作,请记住将这些元素添加到以这种方式序列化的列表中?

PS:如果某些名称空间和名称不是100%匹配的,请进行抽象。我需要用一些虚拟名称替换原始XSD。

0 个答案:

没有答案