[GIS] Open with QGIS a GML file (INSPIRE schema) created with HALE studio

gmlinspireqgisqgis-plugins

I'm trying to export in GML the transformed data of "Basic hydrography example" of hale studio and to add the file in QGIS, using the plugin GML application schema toolbox. The GML exported should be compliant to INSPIRE Hydro – Physical Water schema.
In hale studio I exported the GML as GML(FeatureCollection) leaving the default options, when I add this file in QGIS 2.18 with the plugin it works, instead when I add in QGIS 3 I have the follow error:

An error has occurred while executing Python code:

ValueError: Prefix format reserved for internal use 
Traceback (most recent call last):
  File "C:/Users/bonatop/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gml_application_schema_toolbox\gui\load_wizard_xml.py", line 58, in validatePage
    swap_xy=self.swapXYCheck.isChecked())
  File "C:/Users/bonatop/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gml_application_schema_toolbox\core\load_gml_as_xml.py", line 59, in load_as_xml_layer
    return s.load_complex_gml(xml_uri, is_remote, attributes, geometry_mapping, logger, swap_xy)
  File "C:/Users/bonatop/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gml_application_schema_toolbox\core\load_gml_as_xml.py", line 317, in load_complex_gml
    src = ComplexFeatureSource(xml_src, attributes, geometry_mapping, logger)
  File "C:/Users/bonatop/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gml_application_schema_toolbox\core\load_gml_as_xml.py", line 198, in __init__
    doc, _ = xml_parse(xml)
  File "C:/Users/bonatop/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gml_application_schema_toolbox\core\xml_utils.py", line 94, in xml_parse
    ET.register_namespace(prefix, uri)
  File "C:\PROGRA~1\QGIS 3.4\apps\Python37\lib\xml\etree\ElementTree.py", line 1035, in register_namespace
    raise ValueError("Prefix format reserved for internal use")
ValueError: Prefix format reserved for internal use

I'm new in GML and INSPIRE data schema and I don't understand if I need to set other information for exporting the GML in HALE studio or the problem is in QGIS.

Link to gml file

<?xml version="1.0" ?>
<gml:FeatureCollection xmlns:lc="urn:x-inspire:specification:gmlas:LandCover:0.0" xmlns:sr="urn:x-inspire:specification:gmlas:SeaRegions:0.0" xmlns:nrz="urn:x-inspire:specification:gmlas:NaturalRiskZones:0.0" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty" xmlns:wfd="urn:x-inspire:specification:gmlas:WaterFrameworkDirective:0.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ns1="http://www.w3.org/1999/xhtml" xmlns:hy="urn:x-inspire:specification:gmlas:HydroBase:3.0" xmlns:hy-n="urn:x-inspire:specification:gmlas:HydroNetwork:3.0" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:hy-p="urn:x-inspire:specification:gmlas:HydroPhysicalWaters:3.0" xmlns:net="urn:x-inspire:specification:gmlas:Network:3.2" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gn="urn:x-inspire:specification:gmlas:GeographicalNames:3.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" gml:id="_64fcbf57-4712-471b-941a-a32bf099cb3a" xsi:schemaLocation="urn:x-inspire:specification:gmlas:HydroPhysicalWaters:3.0 http://inspire.ec.europa.eu/schemas/hy-p/3.0/HydroPhysicalWaters.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/deprecatedTypes.xsd">
    <gml:featureMember>
        <hy-p:Watercourse gml:id="_d1a6215e-3185-429f-b9b1-f160437e4f99">
            <gml:description>Contains Ordnance Survey data © Crown copyright and database right 2011</gml:description>
            <hy-p:beginLifespanVersion xsi:nil="true"/>
            <hy-p:geometry>
                <gml:Polygon gml:id="_b71d9cef-6403-4159-8ca3-33892e79a545" srsName="EPSG:27700" srsDimension="2">
                    <gml:exterior>
                        <gml:LinearRing>
                            <gml:posList>389051.4200870958 603715.4762895561 389320.16926064255 603725.4299626504 389321.05757840496 603725.55079575 389321.9052540223 603725.8426092736 389322.67971179605 603726.2941889914 389323.35118974827 603726.888180948 389323.8938833579 603727.6017583656 389324.28693721374 603728.4074988643 389324.51524647657 603729.2744382886 389324.57003734953 603730.1692606426 389324.44920425006 603731.0575784049 389324.1573907264 603731.9052540223 389323.7058110086 603732.6797117961 389323.11181905196 603733.3511897483 389322.3982416343 603733.8938833579 389321.5925011356 603734.2869372137 389320.72556171136 603734.5152464766 389319.83073935745 603734.5700373496 389049.83073935745 603724.5700373496 389049.02376326965 603724.467756975 389048.24767326674 603724.2241261299 389047.5270232105 603723.8468527837 388908.0095929802 603634.1570762071 388699.3754747564 603564.6123701325 388510.24036051735 603574.5668498293 388509.3447938536 603574.525991101 388508.47440639464 603574.3112010731 388507.66264664236 603573.9307340056 388506.9407100688 603573.3992110346 388506.33634029166 603572.7370582899 388505.87276290247 603571.9697219301 388505.5677929204 603571.1266902612 388505.4331501707 603570.2403605173 388505.4740088989 603569.3447938536 388505.6887989269 603568.4744063946 388506.0692659944 603567.6626466423 388506.60078896536 603566.9407100688 388507.26294171 603566.3363402917 388508.03027806984 603565.8727629025 388508.8733097388 603565.5677929204 388509.75963948265 603565.4331501707 388699.75963948265 603555.4331501707 388700.6136181392 603555.4681832207 388701.4461635641 603555.6615093077 388911.4461635641 603625.6615093077 388912.4729767895 603626.1531472163 389051.4200870958 603715.4762895561</gml:posList>
                        </gml:LinearRing>
                    </gml:exterior>
                </gml:Polygon>
            </hy-p:geometry>
            <hy-p:inspireId>
                <base:Identifier>
                    <base:localId>_d1a6215e-3185-429f-b9b1-f160437e4f99</base:localId>
                    <base:namespace>_example</base:namespace>
                </base:Identifier>
            </hy-p:inspireId>
            <hy-p:origin xsi:nil="true"/>
            <hy-p:persistence xsi:nil="true"/>
            <hy-p:tidal xsi:nil="true"/>
            <hy-p:drainsBasin xsi:nil="true"/>
            <hy-p:delineationKnown xsi:nil="true"/>
            <hy-p:length uom="m">848.2407036092494</hy-p:length>
            <hy-p:level xsi:nil="true"/>
            <hy-p:width>
                <hy-p:WidthRange>
                    <hy-p:lower uom="m">4.573170731707317</hy-p:lower>
                    <hy-p:upper uom="m">4.573170731707317</hy-p:upper>
                </hy-p:WidthRange>
            </hy-p:width>
        </hy-p:Watercourse>
    </gml:featureMember>
....
</gml:FeatureCollection>

Best Answer

This is a bug see: https://github.com/BRGM/gml_application_schema_toolbox/issues/83 for details.

The issue is the use of a namespace prefix beginning with ns followed by an integer in the source document created by HALE (this is perfectly legitimate, but causes an error due to a restriction in ElementTree which is called by the GMLAS plugin).

You can get around the issue by changing the prefix, for example from xmlns:ns1 to xmlns:ns_1.

Related Question