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 #1), and now `foo="bar"` highlighted as error, profit:
![screenshot3](https://user-images.githubusercontent.com/688044/46721651-357a0400-cc7c-11e8-9e76-2e047a29fe21.jpg)
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.
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.
There are two points here:
xmlns
was modified inmap/1/map.xsd
(https://github.com/tumic0/GPXSee/commit/4a80f5a613cc8320673e568cc27571ba3962bfdd#diff-ec4a8bbb88358571f4a2abe337396e5e):find . -type f ( -iname *.xml -o -iname *.tpl ) | \ xargs -L1 -P0 -I {} bash -c \ 'xmllint -schema <('
'curl -s
') $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
xml sel -t -v "namespace-uri(/*)" $1
/map.xsd'