4542 -Gml SourceDriverOptions -RestoreSchema

Hi Alexander,

1.Testing Gml input with schema:

Gml → Gml

Please see:

This my commad line:
image.png (34.3 KB)

Input data:
Input.zip (2.1 KB)

Call stack:
Aspose.Gis.GisException
HResult=0x80131500
Message=Failed to build feature attribute collection for file D:\GisConverter\Tests\Gml\Temp\2026-04-29_10-52-08\TestGmlWithSchema\Gml\gml_with_schema.gml. No XML schemas were found. Probably schemaLocation attribute is missing. Consider to set RestoreSchema to true, so Aspose.GIS can parse attributes with the missing schemes.
Source=Aspose.GIS
StackTrace:

This exception was originally thrown at this call stack:
[External Code]
GisConverter.Lib.Converters.UniversalGisConverter.Convert(string, string, string, string, string) in UniversalGisConverter.cs

Waiting to your quick answer.
Thanks

Hi Alexander,

2.Testing Gml input with schema:

Gml → Gml

Please see:

This my commad line:
image.png (31.4 KB)

Input data: please extract the zip/
gml_without_schema.zip (1.1 KB)

Call stack:
Aspose.Gis.GisException: 'Failed to build feature attribute collection for file D:\GisConverter\Tests\Gml\Input\gml_without_schema.gml. Some XML schemas were not loaded since LoadSchemasFromInternet options is set to false. Consider to set it to true, so Aspose.GIS can download them and build feature attributes collection for file. Consider to set RestoreSchema to true, so Aspose.GIS can parse attributes with the missing schemes. ’

Waiting to your quick answer.
Thanks

I used your sample my ConversionOptionsDetector class check if HasGmlSchema
My code is OK ?

This is
///


/// Provides lightweight detection helpers used to infer conversion options from input data.
///

///
/// The detector is stateless and implemented as a static helper to allow inexpensive checks
/// (for example, whether an input archive contains a GML schema file) before selecting conversion
/// strategies. Current checks are conservative and rely on filename / archive entry inspection
/// rather than full content parsing to keep I/O and CPU overhead minimal.
///
/// Behaviour notes:
/// - If the input path references a supported archive (see ),
/// the detector will list the archive entries (via )
/// and return true when any entry ends with the “.xsd” extension (case-insensitive).
/// - For non-archive inputs the current implementation does not attempt to open the file or parse
/// its contents and therefore returns false (no schema found). This keeps fast-path checks cheap.
/// - All I/O and archive-listing errors are caught; the method logs failures and returns false
/// rather than throwing, making it safe to call during pre-flight option detection.
///
/// Thread-safety:
/// - The class is stateless and safe for concurrent use.
///
public static class ConversionOptionsDetector
{

/// <summary>
/// Determines whether the provided input contains a GML schema file (.xsd).
/// </summary>
/// <param name="inputFilePath">The path to the input file. May point to an archive file (zip, etc.).</param>
/// <returns>
/// <c>true</c> when a GML schema file (identified by the ".xsd" extension) is present inside
/// an archive referenced by <paramref name="inputFilePath"/>; otherwise <c>false</c>.
/// </returns>
/// <remarks>
/// Implementation details:
/// - If <paramref name="inputFilePath"/> identifies an archive, the method attempts to enumerate
///   entries and checks for any entry with an ".xsd" extension (case-insensitive).
/// - If no entries are found or the archive cannot be read, the method logs an informational
///   or error message and returns <c>false</c>.
/// - For non-archive paths the method currently performs no content inspection and returns <c>false</c>.
/// - Exceptions thrown during archive detection/listing are caught, logged via <see cref="Log"/>,
///   and suppressed; the method then returns <c>false</c>.
/// </remarks>

public static bool HasGmlSchema(string inputFilePath)
{
    try
    {
        var hasXsd = false;

        var inputIsArchive = ConverterUtils.IsArchiveFile(inputFilePath);
        if (inputIsArchive)
        {
            var entries = ConverterUtils.TryListArchiveEntries(inputFilePath);

            if (entries == null || !entries.Any())
            {
                Log.Info($"[HasGmlSchema] No entries found in archive: {inputFilePath}");
                return false;
            }

             hasXsd = entries.Any(e =>
                !string.IsNullOrEmpty(e) &&
                e.EndsWith(".xsd", StringComparison.OrdinalIgnoreCase));

            Log.Info($"[HasGmlSchema] Archive checked: {inputFilePath}, HasXsd={hasXsd}");

            return hasXsd;
        }

        Log.Info($"[HasGmlSchema] checked: {inputFilePath}, HasXsd={hasXsd}");
        return hasXsd;

    }
    catch (Exception ex)
    {
        Log.Error($"[HasGmlSchema] Error processing archive {inputFilePath}: {ex.Message}", ex);
        return false;
    }
}

}

P.S
I passed all my posts and suggest to close them:)

Thank you!

I will check and back with answer

1.Can you please check with priority?
2. You said: “if you have schema .xsd file for gml then set false, otherwise true”
Does my code is correct ? HasGmlSchema in ConversionOptionsDetector class
Waiting to your quick answer ?
Thanks,

Hi, @danies8
During testing i found incorrect behavior in our code which need to explore deeper.
so, currently for your testing always use GmlOptions { RestoreSchema = true }

We have holiday tomorrow. We go back to work on monday.
Thank you for understand.

Hi Alexander,

I will use “RestoreSchema” in any case and wait for full fix in end of May.
I will put the full code in comment.
Have a happy holiday from all my hurt.

Thanks for everything.

Yes!
Thank you!

Is it fix ? will be in May version ?

Not yet.
We try to fix it in May.

It will be in May ?

Hi, @danies8
I explore deeper and find out that was mistake in example, wrong link to schema.
Try to use this one
Gml_with_schema.zip (996 Bytes)

To use RestoreSchema option like you guide me in past ?

Yes, it will be best way

Hi Alexander,

Here are my results with new corrected file with schema.

All conversions succeeded except Osm that blocked.

1.This my edit code (is OK?):

Caller:
// Build conversion Options
var context = new ConversionContext();

if (gisSourceFormatOption.Equals(“Gml”, StringComparison.OrdinalIgnoreCase))
{
context.HasGmlSchema = ConversionOptionsDetector.HasGmlSchema(gisInputFilePath);
}

var options = ConverterUtils.BuildConversionOptions(
gisSourceFormatOption,
gisTargetFormatOption,
context);

The function please see the bold code:
///


/// Source options strategy for GML inputs.
///

///
/// Provides reader-side option composition for GML source data. This strategy is:
/// - Pure and small: it mutates the supplied only and performs no I/O.
/// - Advisory: it applies configuration based on hints in , where
/// null values are treated as “unknown” and conservative defaults are preserved.
///
/// Behavior:
/// - When == false, the strategy enables
/// so the GML reader will attempt to restore attribute collection
/// schema information that may be required by downstream processing.
/// - When the hint is null or false, the default GML reader behavior is preserved.
///
/// Usage:
/// - Use when composing source driver options (for example via ).
/// - Treat schema restoration as potentially altering parsing semantics; document and test any cases where
/// enabling schema restore changes conversion output.
///
public class GmlSourceStrategy : ISourceOptionsStrategy
{
///
/// Canonical format name handled by this strategy.
///

public string Format => “Gml”;

    /// <summary>
    /// Apply GML-specific source/reader options to the provided <see cref="ConversionOptions"/>.
    /// </summary>
    /// <param name="options">Conversion options to mutate. Must not be null.</param>
    /// <param name="context">Optional conversion context containing hints such as <see cref="ConversionContext.HasGmlSchema"/>.</param>
    /// <remarks>
    /// - Sets <see cref="GmlOptions.RestoreSchema"/> = <c>false</c> when the context has GML schema
    ///   is present. Otherwise sets <see cref="GmlOptions"/> to true to restore the GMLschema.
    /// - The method mutates <paramref name="options"/> only and performs no file I/O.
    /// </remarks>
    public void Apply(ConversionOptions options, ConversionContext context)
    {
        **var gmlOptions = new GmlOptions();**

        **if (context?.HasGmlSchema == true)**

** {**
** gmlOptions.RestoreSchema = false;**
** }**

             gmlOptions.RestoreSchema = true;

        options.SourceDriverOptions = gmlOptions;
    }
}

2.Please see:

Input-Gml
image.png (11.5 KB)

Csv:
The order of the columns not like the input (gml):
image.png (1.7 KB)

Gdb
The location of the point not like the input (gml).

3.Test data(input, output, QGIS)
Task 4542-Gpx with shcema-All formats.zip (51.9 KB)

Hi, @danies8

Good.

It’s ok. It’s because gml_id was like attribute not separate tag. It’s correct.

Only for Gdb ?

Yes only for Gdb.

Hi Alexander,
I need to close this issue to commit my code.
If you can answer it.
Thanks:)

Hi, @danies8
I check you sample and see gdb folder instead of gdbtable and gdbtablx files. how you get it?