I'm fairly new to python and XML and I'm currently working on an XML validator for my firm. I want to check incomming XML files, however, these files do not follow the normal naming with namespaces, so I had a lot of trouble with it. I have found a workaorund, however, I now see that dependent on which version of the software the sender has, the namespace will change. So now my program is not working again.
It is not possible to change anything in the incomming file, and I'm using the python module XMLSchema to validate if that makes a difference.
Is is possible for me to set 2 or more different targetnamespace in my XSD file to workaround the problem? Or is there another solution?
Example of top of incomming XML file:
<?xml version="1.0" encoding="utf-8"?>
<KnudeGroup xmlns="http://www.XXXXX.dk/xml/schemas/XXXXXX/20120102">
<Referencesys>
And the other version of incomming XMl file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<LedningGroup xmlns="http://www.XXXXX.dk/xml/schemas/XXXXX/20140701">
<Referencesys>
My current workaround:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.XXXXX.dk/xml/schemas/XXXXX/20140701">
<xs:element name="LedningGroup">
I have tried to read the different question here and google the problem, but most solutions are to change the XML file, and that is not a possibility in my case.
Changing the namespace when the schema changes is something we usually advise against, for exactly this reason, but people do it anyway so you have to live with it.
One possible approach is "chameleon" namespaces. If a schema document (module) M has no target namespace, you can xs:include it into a schema document that does have a target namespace, and it will "acquire" that namespace; so you can chameleon-include one schema document into two different target namespaces.
The other approach, which I tend to prefer, is to start your processing pipeline by transforming all incoming documents (using XSLT) to use a single namespace, so only the first step in the pipeline needs to worry about namespace variants. The second step in the pipeline can do XSD validation.