是否可以在查询中使用Xpath来使用XQuery获取子父关系。
如果我使用EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML, '<xmlns:ns="http://some_namespace"/>'
,之后使用元数据属性
我会收到正确的亲子关系,即
SELECT *
FROM OPENXML(@hDoc,'/ns:root/ns:component/ns:indicator')
WITH(
componentID INT '@mp:parentid',
indicatorID INT '@mp:id',
componentIndicatorType VARCHAR(5) '@sometype') componentIndicators
这有效,但如果我使用XQuery,则不需要任何sp_xml_preparedocument,而是直接访问存储XML的表,该表在xml列中,其索引类似于
;WITH XMLNAMESPACES (
'http://some_namespace' AS ns )
select
**** --> Here I would like to retrieve a parent -- child relation id
f.i.value(N'@sometype', N'nvarchar(100)') AS sometype
from dbo.xmldatatest AS T
cross apply T.xmldata.nodes('ns:root/ns:component/ns:indicator') as f(i)
当你没有使用xquery在xml中明确地将它作为属性时,是否可以获得这样的节点关系?
其次,当您拥有GB +大小的xml文档时,是否存在与性能和可伸缩性相关的首选方式(OPENXML / XQuery)?