2014-07-14 68 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