2011-10-31 102 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' –