Има ли конкретна причина, поради която трябва да използвате OPENXML, за да направите това? Можете лесно да получите информацията с XQUERY през 2005 г. по следния начин:
declare @xmldata xml
set @xmldata =
'<data xmlns="http://www.aaa.com/master_browse_response" xmlns:dt="http://www.aaa.com/DataTypes">
<products>
<product>
<product_id>121403</product_id>
<countries>
<dt:country>GBR</dt:country>
<dt:country>USA</dt:country>
</countries>
</product>
</products>
</data>'
;WITH XMLNAMESPACES
(
DEFAULT 'http://www.aaa.com/master_browse_response',
'http://www.aaa.com/DataTypes' as dt
)
SELECT x.c.value('(../../product_id)[1]', 'varchar(100)') as product_id,
x.c.value('(.)[1]', 'varchar(100)') as country
FROM @xmldata.nodes('/data/products/product/countries/dt:country') x(c)
По-новите възможности на XQUERY са много по-добър избор за решаване на вашия проблем.
РЕДАКТИРАНЕ:Същото решение с OPENXML би било:
declare @xmldata xml
set @xmldata =
'<data xmlns="http://www.aaa.com/master_browse_response" xmlns:dt="http://www.aaa.com/DataTypes">
<products>
<product>
<product_id>121403</product_id>
<countries>
<dt:country>GBR</dt:country>
<dt:country>USA</dt:country>
</countries>
</product>
</products>
</data>'
DECLARE @hDoc int, @rootxmlns varchar(100)
SET @rootxmlns = '<root xmlns:hm="http://www.aaa.com/master_browse_response" xmlns:dt="http://www.aaa.com/DataTypes"/>'
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmldata, @rootxmlns
SELECT *
FROM OPENXML(@hDoc, '//hm:product/hm:countries/dt:country',2)
WITH(Country varchar(100) '.',
Product_ID varchar(100) '../../hm:product_id')
EXEC sp_xml_removedocument @hDoc