After several days of tweaking i still couldn't get this right. I am trying to read a xml file with lots of namespaces, inserting particular node values to a different table.
XML
<ArrayOfCatalogItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CatalogItem Version="1">
<Container xmlns="http://3ecompany.com/webservices/catalogitemxml">
<ContainerType>Unknown</ContainerType>
<MarkedForRetail xsi:nil="true" />
</Container>
<Documents CultureCode="en" Elink="https://3eonline.com/ImageServer/ImageViewer.aspx?id=3Q%2ffAR8ne%2fvPh6syVnSymkS%2bBDo8OjmbVocxRCMEgeEuoz0WYqIq%2bpG3%2b3wu9B2vvARePPfTWFBb0hg91%2fRYfNzA43I%2baZTLYlibHjHcCDI%3d" Format="Msds" DocumentType="Sds" xmlns="http://3ecompany.com/webservices/catalogitemxml" />
<Documents CultureCode="en" Elink="https://3eonline.com/ImageServer/ImageViewer.aspx?id=3Q%2ffAR8ne%2fvPh6syVnSymniD9dyO5cXo%2bPmAACkW7RMmVjYMZVxizRxXLlqcjbNGgyhjsG5gzhZK9bibPB5EPg%3d%3d" Format="ClientAttachment" DocumentType="Attachment" xmlns="http://3ecompany.com/webservices/catalogitemxml" />
<IsHazardous xmlns="http://3ecompany.com/webservices/catalogitemxml">true</IsHazardous>
<ManufacturerName xmlns="http://3ecompany.com/webservices/catalogitemxml">Sigma-Aldrich</ManufacturerName>
<Msds xmlns="http://3ecompany.com/webservices/catalogitemxml">
<Elink>https://3eonline.com/ImageServer/ImageViewer.aspx?id=3Q%2ffAR8ne%2fvPh6syVnSymqIuIP5CInA01ZbaRQ9r18HUOi1FRQqntYtr58dWAm4wO3rdUO%2bO6MamuvwN7v7fbA%3d%3d</Elink>
<FireCodeClassification>
<MsdsId>8342624</MsdsId>
<Properties>
<PhysicalState>Liquid</PhysicalState>
<BoilingPoint>
<Minimum xsi:nil="true" />
<Range>EqualTo</Range>
<Units>Celsius</Units>
<Value>217.0000</Value>
</BoilingPoint>
</Properties>
<TransportationClassificationCompleted xsi:nil="true" />
<WasteCompleted xsi:nil="true" />
<ExtendedSds>false</ExtendedSds>
<TransportationExceptionClassificationCompleted xsi:nil="true" />
<BestAvailable>false</BestAvailable>
</Msds>
<ProductIdentifiers xmlns="http://3ecompany.com/webservices/catalogitemxml">
<Identifier>4197644</Identifier>
<FlaggedForResend xsi:nil="true" />
</ProductIdentifiers>
<ProductName xmlns="http://3ecompany.com/webservices/catalogitemxml">(3-Aminopropyl)triethoxyeilane - A3648</ProductName>
<ProductUid xmlns="http://3ecompany.com/webservices/catalogitemxml">4d3dc6df9cf24cc6b3ab2b6be8373858</ProductUid>
<IsDeactivated xmlns="http://3ecompany.com/webservices/catalogitemxml">false</IsDeactivated>
<DeactivatedDate xsi:nil="true" xmlns="http://3ecompany.com/webservices/catalogitemxml" />
</CatalogItem>
</ArrayOfCatalogItem>
I need to fetch several values from this xml (I deleted most of the xml for readability). I wrote the sample query to fetch only Identifier and all i get is 'Null' for the column Identifier. I want to fetch ContainerType,MsdsID,PhysicalState,Minimum,
Query
DECLARE @XmlTable TABLE (XMLDATA XML)
INSERT INTO @XmlTable(XMLData)
SELECT CONVERT(XML, BulkColumn) AS BulkColumn
FROM OPENROWSET(BULK 'C:\AAEWRXML.xml', SINGLE_BLOB) AS x;
;WITH XMLNAMESPACES (Default 'http://www.w3.org/2001/XMLSchema','http://3ecompany.com/webservices/catalogitemxml' as CI)
SELECT
Identifier = XmlData.value('(ArrayOfCatalogItem/CatalogItem/ProductIdentifiers/CI:Identifier)[1]', 'varchar(10)'),
From
@XmlTable