【发布时间】:2014-01-16 13:24:45
【问题描述】:
我需要在 xsd 中声明的复杂类型的 contentModel 我的 XSD 如下:
<element name="add">
<complexType>
<sequence>
<element name="no1" type="xsd:int" minOccurs="0"/>
<element name="no2" type="xsd:int" minOccurs="1" maxOccurs="5"/>
</sequence>
</complexType>
我为此使用以下代码:
//elem is ScheamType for the rootnode , in this case it is add
if (elem != null) {
System.out.println("\ncontent of "+elem +" is "+elem.getContentType());
if(elem.getContentType()==3||elem.getContentType()==4)
{
SchemaParticle particle=elem.getContentModel();
for( SchemaParticle p:particle.getParticleChildren())
{
System.out.println("\nchild:"+p.getName()+"\ttype:"+p.getType().getName().getLocalPart());
}
}
但它为 getContentModel() 返回的 SchemaParticle 对象给出了 NullPointerException
代码适用于以下 xsd:
<complexType name="Employee">
<sequence>
<element name="empid" type="xsd:int"/>
<element name="empname" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
【问题讨论】:
-
回答您的问题需要通读 100 行代码。通过仅发布相关位来减少您的代码示例。另外,为什么不提供导致 XSD 验证错误的 XML 输出?你不觉得这可能有帮助吗?
-
@hugh 现在你可以看看,我正在读取包含 XSD 的 wsdl 文件。