Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML Table Extraction

User_LT7WCOct 4 2022

Hi. I was trying to create columns for "Street, City, State and Zip". The current code lists all Home info in one column. I tried using dot notation and / in the PATH section, but can't seem to get it to work. If anyone has any insight I'd appreciate it, thank you!

with t as (
  select XMLType(
  '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <FindPersonResponse xmlns="http://tempuri.org">
         <FindPersonResult xsi:type="s01:Employee" xmlns:s01="http://tempuri.org">
            <Name>Gibbs,Patrick N.</Name>
            <SSN>295-50-6545</SSN>
            <DOB>1945-09-05</DOB>
            <Home>
               <Street>590 Elm Drive</Street>
               <City>Larchmont</City>
               <State>SD</State>
               <Zip>34105</Zip>
            </Home>
            <Office>
               <Street>2298 Maple Street</Street>
               <City>Ukiah</City>
               <State>OH</State>
               <Zip>34636</Zip>
            </Office>
            <Spouse>
               <Name>Quince,Brenda E.</Name>
               <SSN>743-37-2766</SSN>
               <DOB>1952-07-13</DOB>
               <Home>
                  <Street>5370 Main Street</Street>
                  <City>Gansevoort</City>
                  <State>SD</State>
                  <Zip>33945</Zip>
               </Home>
               <Office>
                  <Street>1197 Washington Court</Street>
                  <City>Boston</City>
                  <State>MT</State>
                  <Zip>89506</Zip>
               </Office>
               <Age>70</Age>
            </Spouse>
            <FavoriteColors>
               <FavoriteColorsItem>Purple</FavoriteColorsItem>
               <FavoriteColorsItem>Black</FavoriteColorsItem>
            </FavoriteColors>
            <Age>77</Age>
            <Title>Executive WebMaster</Title>
            <Salary>950</Salary>
         </FindPersonResult>
      </FindPersonResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>')xml_data
from dual
)
select xmlresponse.*
from t,
     XMLTable(
       XMLNamespaces(	
	'http://schemas.xmlsoap.org/soap/envelope/' AS "SOAP-ENV",
	'http://tempuri.org' AS "ds"),
'SOAP-ENV:Envelope/SOAP-ENV:Body/ds:FindPersonResponse/ds:FindPersonResult'
		passing xml_data
       		columns
	Name varchar2(100) PATH 'ds:Name',
	SSN varchar2(100) PATH 'ds:SSN',
	DOB varchar2(100) PATH 'ds:DOB',
	Home varchar2(100) PATH 'ds:Home',
	Office varchar2(100) PATH 'ds:Office',
	Spouse varchar2(100) PATH 'ds:Spouse',
	FavoriteColors varchar2(100) PATH 'ds:FavoriteColors',
	Age varchar2(100) PATH 'ds:Age',
	Title varchar2(100) PATH 'ds:Title',
	Salary varchar2(100) PATH 'ds:Salary'
	 ) xmlresponse;
This post has been answered by mathguy on Oct 4 2022
Jump to Answer
Comments
Post Details
Added on Oct 4 2022
5 comments
427 views