0

i am trying to use XPath to extract data from XML Field in Oracle. So basically, when i am trying to Extract the SessionID from the XML Filed using XPath expression - //SessionID , i get 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. I have realized that there is a problem with xmlns attribute, and that is why it wil not work as intended. Anyone can help me with this? On how to delete xmlns attribute, or bypass it somehow.

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.

Thanks in advance for the help.

1 Answer 1

0

If you want to just ignore the namespace, just use the local-name() function as such:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.