2014-07-14 66 views
0

我正嘗試使用XPath從Oracle中的XML字段提取數據。 所以基本上,當我試圖從XML提取使用XPath表達式的SessionID -// SessionID,我得到空。 爲了得到所需的輸出,我必須做一些像/ */* [1]/text(),這不是很好,因爲如果結構改變,它將無法工作。 我意識到xmlns屬性存在問題,這就是爲什麼它不能按預期工作。 任何人都可以幫助我嗎?關於如何刪除xmlns屬性,或者以某種方式繞過它。XPath,解析XML並刪除Oracle中的XML屬性

下面是我用來得到正確答案的表達式。

select EXTRACT(XMLTYPE('<Session xmlns="http://www.tibco.com" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SessionID>ASDASDASD</SessionID></Session>'),'/*/*[1]/text()') 

from dual;我試過使用Deletexml,但它不會與xmlns(它適用於其他屬性,但不是xmlns),所以我想這不是他的解決方案。

在此先感謝您的幫助。

回答

0

如果你想忽略的命名空間,只需要使用本地名稱()函數,例如:

SELECT EXTRACT (
      XMLTYPE (
      '<Session xmlns="http://www.tibco.com" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SessionID>ASDASDASD</SessionID></Session>'), 
      '//*[local-name() = "SessionID"]/text()') from dual