我有 xsd 架构:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="urn:v1"
xmlns="urn:v1"
xmlns:reg="urn:v1"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.1.1">
<xs:simpleType name="ItemType">
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ListItemType">
<xs:list itemType="ItemType"/>
</xs:simpleType>
<xs:complexType name="Element">
<xs:sequence>
<xs:element name="SubElement">
<xs:complexType>
<xs:sequence>
<xs:element name="SubSubElement" type="ListItemType" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
和 JIBX 生成的 java 类:
public class Element
{
private java.util.List<String> subElements = new java.util.ArrayList<String>();
/**
* Get the list of 'SubSubElement' element items.
*
* @return list
*/
public java.util.List<String> getSubElements() {
return subElements;
}
/**
* Set the list of 'SubSubElement' element items.
*
* @param list
*/
public void setSubElements(java.util.List<String> list) {
subElements = list;
}
/**
* Serializer for 'SubSubElement' element list.
*
* @param values
* @return text
*/
public static String serializeSubElements(java.util.List<String> values) {
if (values == null) {
return null;
} else {
java.lang.StringBuffer buff = new java.lang.StringBuffer();
for (java.util.Iterator<String> iter = values.iterator(); iter
.hasNext();) {
if (buff.length() > 0) {
buff.append(' ');
}
String value = iter.next();
buff.append(value);
}
return buff.toString();
}
}
/**
* Deserializer for 'SubSubElement' element list.
*
* @param text
* @return values
* @throws org.jibx.runtime.JiBXException on conversion error
*/
public static java.util.List<String> deserializeSubElements(String text)
throws org.jibx.runtime.JiBXException {
org.jibx.runtime.IListItemDeserializer ldser = new org.jibx.runtime.IListItemDeserializer() {
public java.lang.Object deserialize(String text) {
return text;
}
};
return (java.util.List<String>) org.jibx.runtime.Utility
.deserializeList(text, ldser);
}
}
我如何检查元素是否可空?我在 xsd 中有:nillable="true"
更新:
好的一些没有列表的esier xsd:
<xs:schema targetNamespace="urn:v1" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.1.1" xmlns="urn:v1" xmlns:reg="urn:v1" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Element">
<xs:sequence minOccurs="0">
<xs:element name="SubElement" type="type1" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="type1">
<xs:restriction base="xs:string" />
</xs:simpleType>
</xs:schema>
public class Element
{
private String subElement;
/**
* Get the 'SubElement' element value.
*
* @return value
*/
public String getSubElement() {
return subElement;
}
/**
* Set the 'SubElement' element value.
*
* @param subElement
*/
public void setSubElement(String subElement) {
this.subElement = subElement;
}
}
再次不可空