6

I use DataSource generated from xsd schema. I need to get all fields from DataSource, also nested ones. My problem is the same like in this topic from Smartclient forum forum, when I use DataSource.getFields() its return only first level fields.

Does anyone know how can I get also nested fields?

Josh Davenport-Smith
  • 5,456
  • 2
  • 29
  • 40
Mariusz
  • 61
  • 4

2 Answers2

1

I m not exactly sure if this will solve your issue. CompanySlaves is not references in any where in xsd. Type is defined but not used.

I think you need to have <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>
Ozgur
  • 258
  • 3
  • 13
0

I found solution. To get nested fields it’s possible to use DataSource.getDataSource(ID). For example, if dataSource is main DataSource, it can be done like that:

    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;
    }

Mariusz
  • 61
  • 4