Example #1
0
static void print_attributes(FILE *f, coda_type *type)
{
    coda_type *attributes;
    long num_record_fields;
    long i;

    coda_type_get_attributes(type, &attributes);
    coda_type_get_num_record_fields(attributes, &num_record_fields);
    for (i = 0; i < num_record_fields; i++)
    {
        coda_type_class field_type_class;
        coda_type *field_type;
        const char *real_name;
        int available;

        coda_type_get_record_field_real_name(attributes, i, &real_name);
        coda_type_get_record_field_available_status(attributes, i, &available);
        coda_type_get_record_field_type(attributes, i, &field_type);
        coda_type_get_class(field_type, &field_type_class);
        fprintf(f, "<xs:attribute name=\"%s\"", real_name);
        if (available == 1)
        {
            fprintf(f, " use=\"required\"");
        }
        switch (field_type_class)
        {
            case coda_integer_class:
                fprintf(f, " type=\"xs:integer\"");
                break;
            case coda_real_class:
                fprintf(f, " type=\"xs:float\"");
                break;
            case coda_text_class:
                fprintf(f, " type=\"xs:string\"");
                break;
            default:
                assert(0);
                exit(1);
        }
        fprintf(f, "/>");
    }
}
Example #2
0
static int get_product_group_availability(coda_product *product, const char *group_name, int *group_available)
{
    coda_type *root_type;
    long num_fields;
    long i;

    if (coda_get_product_root_type(product, &root_type) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }
    if (coda_type_get_num_record_fields(root_type, &num_fields) != 0)
    {
        harp_set_error(HARP_ERROR_CODA, NULL);
        return -1;
    }

    for (i = 0; i < num_fields; i++)
    {
        const char *field_name;

        if (coda_type_get_record_field_real_name(root_type, i, &field_name) != 0)
        {
            harp_set_error(HARP_ERROR_CODA, NULL);
            return -1;
        }

        if (strcmp(field_name, group_name) == 0)
        {
            *group_available = 1;
            return 0;
        }
    }

    *group_available = 0;

    return 0;
}
Example #3
0
static void print_xml_element(FILE *f, coda_type *type)
{
    coda_type_class type_class;
    long num_record_fields;
    long i;

    coda_type_get_class(type, &type_class);
    assert(type_class == coda_record_class);

    fprintf(f, "<xs:complexType><xs:sequence>");
    coda_type_get_num_record_fields(type, &num_record_fields);
    for (i = 0; i < num_record_fields; i++)
    {
        coda_type_class field_type_class;
        coda_type *field_type;
        const char *real_name;
        coda_format format;

        coda_type_get_record_field_real_name(type, i, &real_name);
        coda_type_get_record_field_type(type, i, &field_type);
        coda_type_get_class(field_type, &field_type_class);
        coda_type_get_format(field_type, &format);
        fprintf(f, "<xs:element name=\"%s\"", real_name);
        if (field_type_class == coda_array_class && format == coda_format_xml)
        {
            fprintf(f, " minOccurs=\"0\" maxOccurs=\"unbounded\"");
            coda_type_get_array_base_type(field_type, &field_type);
            coda_type_get_class(field_type, &field_type_class);
            coda_type_get_format(field_type, &format);
        }
        if (field_type_class == coda_special_class)
        {
            coda_type_get_special_base_type(field_type, &field_type);
            coda_type_get_class(field_type, &field_type_class);
            coda_type_get_format(field_type, &format);
        }
        if (field_type_class == coda_record_class)
        {
            fprintf(f, ">");
            print_xml_element(f, field_type);
        }
        else
        {
            const char *xsdtype;
            int has_attributes;

            switch (field_type_class)
            {
                case coda_array_class:
                    assert(format != coda_format_xml);
                    xsdtype = "string";
                    break;
                case coda_integer_class:
                    xsdtype = "integer";
                    break;
                case coda_real_class:
                    xsdtype = "float";
                    break;
                case coda_text_class:
                    xsdtype = "string";
                    break;
                default:
                    assert(0);
                    exit(1);
            }
            coda_type_has_attributes(field_type, &has_attributes);
            if (has_attributes)
            {
                fprintf(f, ">");
                fprintf(f, "<xs:complexType>");
                fprintf(f, "<xs:simpleContent>");
                fprintf(f, "<xs:extension base=\"xs:%s\">", xsdtype);
                print_attributes(f, field_type);
                fprintf(f, "</xs:extension>");
                fprintf(f, "</xs:simpleContent>");
                fprintf(f, "</xs:complexType>");
            }
            else
            {
                fprintf(f, " type=\"xs:%s\">", xsdtype);
            }
        }
        fprintf(f, "</xs:element>");
    }
    fprintf(f, "</xs:sequence>");
    print_attributes(f, type);
    fprintf(f, "</xs:complexType>");
}