Reputation: 19184
I'm using SSIS to import XML files.
When I try to generate XSD it shows the error:
Unable to infer the XSD from the XML file. The XML contains multiple namespaces
Here a very basic sanitised version of the XML file:
<?xml version="1.0"?>
<SM>
<xF>
<MA xmlns="http://www.somewhere.com/ZZ/ZZ.xsd">
</SM>
.... other stuff ...
</xF>
It definitely only has one xmlns=
in it, and it has no namespace qualifiers, a bit like this:
Unable to infer XSD from XML file .XML contain Multiple Namespaces
....except that there are no namespace qualifiers (the only :
in the file is in the URL)
If it only has one xmlns=
in it, doesn't that mean it only has one namespace, not many?
If there is some kind of 'inherent' namespace, that means that SSIS is unable to import any xml file with a xmlns=
declaration in it.
Can anyone clarify: how many namespaces does an XML file with only one xmlns=
in it have? Is there a tool I can use that will enumerate the namespaces so I can identify them?
There are many online solutions that say "remove the xmlns with xlst" but I would rather first understand why SSIS thinks it has multiple namespaces.
If I remove the xmlns part, generate the XSD and import it imports OK. If I leave the xmlns in and import with the existing XSD it imports no rows. I think this is because the XSD needs to refer to the namespace, but if I put targetNamespace
into the XSD, it still imports no rows. Perhaps I need to find a non SSIS XML tool to do some investigation.
Upvotes: 2
Views: 4055
Reputation: 19184
After a bit of thinking and reading I moved the xmlns to the top:
<?xml version="1.0"?>
<SM xmlns="http://www.somewhere.com/ZZ/ZZ.xsd">
<xF>
<MA>
</SM>
.... other stuff ...
</xF>
and no longer got the error. I think perhaps just the top half of the document has some kind of default (blank?) namespace, until it got to the xmlns part, where the default was changed, and that's the issue.
Putting this together with the accepted answer: there is only one namespace and the error message is misleading. The practical solution is to remove the xmlns or move it into the first element
This follows the definition of 'default namespaces' described at this link: http://www.w3schools.com/xml/xml_namespaces.asp
Upvotes: 2
Reputation: 38238
Technically, the error is a little misleading. Your original document contains a mix of elements, some of which have no namespace, and some of which have a namespace. The namespace declaration on your MA
element actually declares "http://www.somewhere.com/ZZ/ZZ.xsd" as a default namespace for elements and attributes below it, as it doesn't have a prefix.
So to answer your question, your document has one namespace. However, it contains elements that have no namespace along with elements that are in your one namespace, and this is presumably what's confusing SSIS.
Upvotes: 2