2016-03-03 85 views
4

可以有一个人请帮助提取此:OPENXML与命名空间

<Customize xmlns="http://utsavfashion.com/web/schemas"> 
    <customize_details> 
     <entityid>876</entityid>  
    </customize_details> 
</Customize> 

我使用:

DECLARE @xml_hndl INT 
EXEC sp_xml_preparedocument @xml_hndl OUTPUT, @str 

SELECT * 
FROM OPENXML(@xml_hndl, '/Customize/customize_details', 2) 
WITH (entityid INT) 

EXEC sp_xml_removedocument @xml_hndl 

,我没有得到任何东西,除非我从XML

+1

OPENXML绝对过时。您应该使用XML方法,比如'.value()','.query()'或'.nodes()'。 – Shnugo

回答

4

XQuery的删除命名空间:

DECLARE @x XML = ' 
<Customize xmlns="http://utsavfashion.com/web/schemas"> 
    <customize_details> 
     <entityid>876</entityid>  
    </customize_details> 
</Customize>' 

SELECT t.c.value('.', 'INT') 
FROM @x.nodes('*:Customize/*:customize_details/*:entityid') t(c) 

OpenXM L:

DECLARE @x XML = ' 
<Customize xmlns="http://utsavfashion.com/web/schemas"> 
    <customize_details> 
     <entityid>876</entityid>  
    </customize_details> 
</Customize>' 

DECLARE @doc INT, @xmlns VARCHAR(100) 

SET @xmlns = '<root xmlns:h="http://utsavfashion.com/web/schemas" />' 
EXEC sp_xml_preparedocument @doc OUTPUT, @x, @xmlns 

SELECT * 
FROM OPENXML(@doc, '//h:Customize/h:customize_details') 
    WITH (
     entityid INT '.' 
    ) 

EXEC sp_xml_removedocument @doc 
+0

谢谢Devart ......但是可以在openxml中完成同样的工作吗? –

+0

@sachin kalra请检查更新 – Devart

+0

完美....非常感谢@Devart –