XSD与SSIS报错:无法找到全局声明的复杂类型
I’ve dealt with this exact SSIS XML mapping issue multiple times, and the root cause here is almost always namespace resolution—even though you’ve declared your Bus complex type globally, SSIS isn’t associating it with the target namespace you’ve defined.
Let’s break down what’s happening in your XSD:
- You’ve set a
targetNamespace="urn:Search"on your schema - Your global
Buscomplex type lives in this namespace, but when you reference it in theBuselement (type="Bus"), you aren’t specifying the namespace prefix. SSIS’s XML parser can’t find the type because it’s looking in the default (empty) namespace instead ofurn:Search.
Step 1: Update Your XSD to Use Namespace Prefixes
Modify your XSD to add a namespace alias for your target namespace, and explicitly reference the Bus type using that alias:
<?xml version="1.0"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:Search" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns="urn:Search"> <!-- Add this namespace alias --> <xs:element name="RESPONSE"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="ABC"> <xs:complexType> <xs:sequence> <!-- Reference the Bus type with the namespace prefix --> <xs:element minOccurs="0" maxOccurs="1" name="Bus" type="ns:Bus" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="Bus"> <xs:sequence> <xs:element minOccurs="0" maxOccurs="1" name="BusType" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="1" name="BusSubType" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="1" name="Date" type="xs:string" /> <xs:element minOccurs="1" maxOccurs="1" name="Franchise" type="xs:boolean" /> <xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="1" name="OperatingSince" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:schema>
Step 2: Configure SSIS XML Source to Handle Namespaces
After updating the XSD, open your SSIS package’s XML Source editor:
- Go to the Columns tab, then click the Advanced button
- In the Advanced Editor, navigate to the Input and Output Properties tab
- Under XML Source Output > Output Columns, ensure all columns are correctly mapped
- Crucially, go back to the Connection Manager tab and make sure the Namespace dropdown is set to Use Namespaces (not "Ignore Namespaces")
Step 3: Troubleshooting Extra Checks
If you still see the error after the above steps:
- Close and reopen the SSIS Visual Studio project (sometimes the design caches old XSD definitions)
- Verify that your XML file actually uses the
urn:Searchnamespace (e.g.,<RESPONSE xmlns="urn:Search">at the root) - Double-check that the XSD path in the XML Source connection manager is pointing to your updated file
This should resolve the "type is not declared" error, as SSIS will now correctly associate your global Bus complex type with its target namespace.
内容的提问来源于stack exchange,提问作者rracca

