2011-10-31 103 views
1

我有以下XML在SQL Server解析2008在XPath动态选择的节点在SQL Server 2008中

<Root> 
    <Document> 
    <Body> 
     <Component> 
     </Component> 
    </Body> 
    </Document> 
</Root> 

我想找回我的XML所有<Component>标签,问题是,有时<Document>标签可能不来,因此我的xpath查询(root/document/body)将不起作用。有没有办法可以得到所有<Component>标签,而不管<Document>标签的存在?

回答

2

你总是可以使用的

//component 

XPath查询,让您的整个文档中的所有<component>元素 - 无论他们在哪里,什么其他的标签也有它周围

+0

或者,如果你喜欢这个想要更具体些。 '/根//车身/ Component' –