xsd验证文件:<xs:element name="RowEnd" type="xs:short" nillable="true"/>
xml文件: <RowEnd/>
验证时一直报如下错误:'' is not a valid value for 'integer'.
The value '' of element 'RowEnd' is not valid.
[b]问题补充:[/b]
没问题,属性值就是nillable这个可以确定
[b]问题补充:[/b]
正常情况应该是nillable=true该属性就可以为空值,难道java不支持,觉得不太可能,验证代码如下:
public static void main(String[] args) throws SAXException, IOException {
// 建立schema工厂
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// 建立验证文档文件对象,利用此文件对象所封装的文件进行schema验证
File schemaFile = new File("schema"+File.separator+"0x3808.xsd");
// 利用schema工厂,接收验证文档文件对象生成Schema对象
Schema schema = schemaFactory.newSchema(schemaFile);
// 通过Schema产生针对于此Schema的验证器,利用students.xsd进行验证
Validator validator = schema.newValidator();
// 得到验证的数据源,就是students.xml
Source source = new StreamSource("schema"+File.separator+"0x3808.xml");
// 开始验证,成功输出success!!!,失败输出fail
try {
validator.validate(source);
System.out.println("验证成功!!");
} catch (Exception ex) {
System.out.println("验证错误 ,出错信息为:");
System.out.println(ex.getMessage());
}
}
看看这篇:
XSD nillable types
[quote]http://www.coderanch.com/t/147320/XML-Certification/XSD-nillable-types[/quote]
意思是说:可以对数值类可以定义为nillable=“true”,同时,还好定义自己的类型。
nillable????
是不是
nullable
http://www.w3school.com.cn/schema/schema_complex_empty.asp
看看这个。。。定义空元素