我使用SSIS导入XML文件。
当我尝试生成XSD时,它显示错误:
无法从XML文件中推断出XSD。 XML包含多个名称空间
这是XML文件的一个非常基本的清理版本:
<?xml version="1.0"?>
<SM>
<xF>
<MA xmlns="http://www.somewhere.com/ZZ/ZZ.xsd">
</SM>
.... other stuff ...
</xF>
它肯定只有一个xmlns=
,它没有命名空间限定符,有点像这样:
Unable to infer XSD from XML file .XML contain Multiple Namespaces
....除了没有命名空间限定符(文件中唯一的:
在URL中)
如果它只有一个xmlns=
,那是不是意味着它只有一个命名空间,而不是很多?
如果存在某种固有的&#39;命名空间,这意味着SSIS无法导入任何带有xmlns=
声明的xml文件。
任何人都可以澄清:一个只有一个xmlns=
的XML文件有多少名称空间?是否有一个我可以使用的工具,它将枚举命名空间,以便我可以识别它们?
有许多在线解决方案说&#34;用xlst&#34;删除xmlns;但我宁愿首先理解为什么SSIS认为它有多个名称空间。
如果我删除xmlns部分,生成XSD并导入它导入OK。如果我将xmlns保留并使用现有XSD导入,则不会导入任何行。我认为这是因为XSD需要引用命名空间,但如果我将targetNamespace
放入XSD,它仍然不会导入任何行。也许我需要找一个非SSIS XML工具来做一些调查。
答案 0 :(得分:1)
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.
答案 1 :(得分:1)
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