简体   繁体   English

XPath,在Oracle中解析XML并删除XML属性

[英]XPath, parsing XML and deleting XML attributes in Oracle

i am trying to use XPath to extract data from XML Field in Oracle. 我正在尝试使用XPath从Oracle中的XML字段提取数据。 So basically, when i am trying to Extract the SessionID from the XML Filed using XPath expression - //SessionID , i get null. 因此,基本上,当我尝试使用XPath表达式-// SessionID从XML Filed中提取SessionID时,我得到了null。 To get the desired output i have to do something like /* / *[1] /text(), which is not very good, cuz if the structure changes, it will not work. 为了获得所需的输出,我必须执行类似/ * / * [1] / text()的操作,这不是很好,因为结构改变,它将无法正常工作。 I have realized that there is a problem with xmlns attribute, and that is why it wil not work as intended. 我已经意识到xmlns属性存在问题,这就是为什么它无法按预期工作的原因。 Anyone can help me with this? 有人可以帮我吗? On how to delete xmlns attribute, or bypass it somehow. 关于如何删除xmlns属性或以某种方式绕过它。

Here is the expression that i am using to get the proper answer. 这是我用来获取正确答案的表达方式。

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; 从双重

I have tried using Deletexml, but it will not work with xmlns (it works with other attributes, but not xmlns), so i guess that is not he solution. 我曾尝试使用Deletexml,但它不适用于xmlns(它可与其他属性一起使用,但不适用于xmlns),所以我想那不是他的解决方案。

Thanks in advance for the help. 先谢谢您的帮助。

If you want to just ignore the namespace, just use the local-name() function as such: 如果您只想忽略名称空间,则可以使用local-name()函数,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM