tumic0 / GPXSee-maps

GPXSee maps
https://maps.gpxsee.org
The Unlicense
33 stars 10 forks source link

Fix failed xml validations #18

Closed sikmir closed 5 years ago

sikmir commented 5 years ago

There are two points here:

  1. Some XML validations fail after xmlns was modified in map/1/map.xsd (https://github.com/tumic0/GPXSee/commit/4a80f5a613cc8320673e568cc27571ba3962bfdd#diff-ec4a8bbb88358571f4a2abe337396e5e):
    
    $ cat << 'EOF' > validate.sh
    #!/bin/sh

find . -type f ( -iname *.xml -o -iname *.tpl ) | \ xargs -L1 -P0 -I {} bash -c \ 'xmllint -schema <(' 'curl -s xml sel -t -v "namespace-uri(/*)" $1/map.xsd' ') $1 --noout' _ {} 2>&1 | sort EOF $ chmod +x validate.sh $ ./validate.sh | tail -n 2 ./World/unesco.xml:2: element map: Schemas validity error : Element '{http://www.gpxsee.org/map/1}map': No matching global declaration available for the validation root. ./World/unesco.xml fails to validate $ ./validate.sh | grep -c "validates" 12 $ ./validate.sh | grep -c "fails to validate" 30


2. Allow XML editors to validate the XML file against its specified `xsi:schemaLocation` on the fly (no need to run `validate.sh` script before commit).

Bellow is an example from _Visual Studio Code_ (with _XML Tools_ extension):

- We have some error here (`foo="bar"`), but editor have no idea about it:
![screenshot1](https://user-images.githubusercontent.com/688044/46721649-357a0400-cc7c-11e8-8df7-5418a4c71cdc.jpg)
- Let's add `xmlns:xsi` and `xsi:schemaLocation` attributes, much better:
![screenshot2](https://user-images.githubusercontent.com/688044/46721650-357a0400-cc7c-11e8-9b6f-9edc8e6b30bb.jpg)
- Let's fix `xmlns` (see point #&#xfeff;1), and now `foo="bar"` highlighted as error, profit:
![screenshot3](https://user-images.githubusercontent.com/688044/46721651-357a0400-cc7c-11e8-9e76-2e047a29fe21.jpg)
tumic0 commented 5 years ago
  1. I have fixed the XSDs in tumic0/GPXSee@bf58ae296b724374706ab310eed891994255c382. "Fixing" the xmlns can not be done here in the repo as other "version 1" maps out there would still not be validable.
  2. Adding the two attributes makes the XML look too complex for me (most people won't know what they are good for and whether they are required). As the XML is created and validated once (which can still be done), but read many times, I would not over-complicate things and let the XMLs as they are.