我使用从xsd模式生成的DataSource。我需要从DataSource获取所有字段,也包括嵌套字段。我的问题和在this topic from Smartclient forum forum中一样,当我使用DataSource.getFields()时,它只返回第一级字段。
有人知道怎样才能得到嵌套的字段吗?
发布于 2012-10-23 02:02:44
我找到了解决方案。要获得嵌套字段,可以使用DataSource.getDataSource(ID)。例如,如果dataSource是主DataSource,则可以这样做:
private List<DataSourceField> getAllFields(DataSource dataSource)
{
List <DataSourceField> fieldList = new ArrayList<DataSourceField>();
DataSourceField [] fields = dataSource.getFields();
fieldList.addAll(Arrays.asList(fields));
for (DataSourceField field : fields);
{
String fieldName = field.getName();
DataSource ds = DataSource.getDataSource(fieldName);
if (ds != null)
{
fieldList.remove(field);
DataSourceField[] nFields = ds.getFields();
fieldList.addAll(Arrays.asList(nFields));
getAllFields(ds);
}
}
return fieldList;
}发布于 2012-10-21 13:35:49
我不太确定这是否能解决你的问题。CompanySlaves在xsd中的任何地方都不是引用。类型已定义,但未使用。
我觉得你需要让<xsd:element name="SomeElementName" type="tns:CompanySlaves"></xsd:element> in your xsd definition
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/newXmlSchema"
xmlns:tns="http://xml.netbeans.org/schema/newXmlSchema"
elementFormDefault="qualified">
<xsd:element name="SubrogationClaim" type="tns:SubrogationClame"></xsd:element>
<xsd:complexType name="SubrogationClame">
<xsd:sequence>
<xsd:element name="CompanyName" type="xsd:string"></xsd:element>
<xsd:element name="CompanyPlace" type="xsd:string"></xsd:element>
<xsd:element name="CompanyEmploee" type="tns:SubrogationClame"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="CompanySlaves">
<xsd:sequence>
<xsd:element name="EmploeeName" type="xsd:string"></xsd:element>
<xsd:element name="EmploeeSalary" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:ComplexType>
</xsd:schema>https://stackoverflow.com/questions/12952221
复制相似问题