dbTalk Databases Forums  

xmltable and namespaces

comp.databases.oracle.server comp.databases.oracle.server


Discuss xmltable and namespaces in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Richard Maher
 
Posts: n/a

Default xmltable and namespaces - 02-03-2011 , 05:43 AM






Hi,

The following code will stop working if I remove the (xmlns=""). As I don't
control the web-service that generates the XML (and omits the null namespace
specification) how can I persuade Oracle to parse the XML correctly so as to
pluck out the EmployeeID attribute?

The only other way (after many, many incantations) that I got it to work was
introducing a new xmltable for every level/qualification. Can someone please
provide an alternative that does not require the xmlns="" property?

Cheers Richard Maher

declare

soap_resp varchar(32767);

resp sys.xmltype;



begin

soap_resp := '<GetStaffDetailsResponse
xmlns="https://www.axby.com/staffQuery/">

<GetStaffDetailsResult>

<StaffDetails xmlns="">

<AuEduPersonPreferredGivenName>Bruce</AuEduPersonPreferredGivenName>

<AuEduPersonPreferredSurname>Coad</AuEduPersonPreferredSurname>

<EmployeeID>000715BC</EmployeeID>

</StaffDetails>

</GetStaffDetailsResult>

</GetStaffDetailsResponse>';



resp := xmltype.createxml(soap_resp);



for i in (

select

Staff.PersonId

from

xmltable

( XmlNamespaces('https://www.axby.com/staffQuery/' as SQ),

'/SQ:GetStaffDetailsResponse'

passing resp

columns

xmlresult xmltype path 'SQ:GetStaffDetailsResult/StaffDetails'

) soapXML

, xmltable

( '*'

passing soapXML.xmlresult

columns

PersonId varchar2(8) path 'EmployeeID'

) Staff )

loop

dbms_output.put_line('hello '||i.PersonID);

end loop;



end;

Reply With Quote
  #2  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: xmltable and namespaces - 02-03-2011 , 12:10 PM






declare
soap_resp varchar(32767);
resp sys.xmltype;
begin
soap_resp := '<GetStaffDetailsResponse
xmlns="https://www.axby.com/staffQuery/">
<GetStaffDetailsResult>
<StaffDetails>
<AuEduPersonPreferredGivenName>Bruce</AuEduPersonPreferredGivenName>
<AuEduPersonPreferredSurname>Coad</AuEduPersonPreferredSurname>
<EmployeeID>000715BC</EmployeeID>
</StaffDetails>
</GetStaffDetailsResult>
</GetStaffDetailsResponse>';

resp := xmltype.createxml(soap_resp);

for r in (
select
extractvalue(
resp,
'/ns:GetStaffDetailsResponse/ns:GetStaffDetailsResult/ns:StaffDetails/ns:EmployeeID',
'xmlns:ns="https://www.axby.com/staffQuery/"') X
from dual
) loop
dbms_output.put_line('Hello:' || r.X);
end loop;
end;
/

this will stop working of you have more than one employee, but then you should look at xmlsequence

Reply With Quote
  #3  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: xmltable and namespaces - 02-03-2011 , 12:28 PM



declare
soap_resp varchar(32767);
resp sys.xmltype;
begin
soap_resp := '<GetStaffDetailsResponse
xmlns="https://www.axby.com/staffQuery/">
<GetStaffDetailsResult>
<StaffDetails>
<AuEduPersonPreferredGivenName>Bruce</AuEduPersonPreferredGivenName>
<AuEduPersonPreferredSurname>Coad</AuEduPersonPreferredSurname>
<EmployeeID>000715BC</EmployeeID>
</StaffDetails>
</GetStaffDetailsResult>
</GetStaffDetailsResponse>';

resp := xmltype.createxml(soap_resp);

for r in (
select
extractvalue(
resp,
'/GetStaffDetailsResponse/GetStaffDetailsResult/StaffDetails/EmployeeID',
'xmlns="https://www.axby.com/staffQuery/"') X
from dual
) loop
dbms_output.put_line('Hello:' || r.X);
end loop;
end;
/


Thanks to Flavio Casetta's "Annals of Oracle's Improbable Errors" :
http://oraclequirks.blogspot.com/200...d-default.html

Reply With Quote
  #4  
Old   
Richard Maher
 
Posts: n/a

Default Re: xmltable and namespaces - 02-03-2011 , 04:52 PM



"Gerard H. Pille" <ghp (AT) skynet (DOT) be> wrote

Quote:
declare
soap_resp varchar(32767);
resp sys.xmltype;
begin
soap_resp := '<GetStaffDetailsResponse
xmlns="https://www.axby.com/staffQuery/"
GetStaffDetailsResult
StaffDetails
AuEduPersonPreferredGivenName>Bruce</AuEduPersonPreferredGivenName
AuEduPersonPreferredSurname>Coad</AuEduPersonPreferredSurname
EmployeeID>000715BC</EmployeeID
/StaffDetails
/GetStaffDetailsResult
/GetStaffDetailsResponse>';

resp := xmltype.createxml(soap_resp);

for r in (
select
extractvalue(
resp,

'/GetStaffDetailsResponse/GetStaffDetailsResult/StaffDetails/EmployeeID',
'xmlns="https://www.axby.com/staffQuery/"') X
from dual
) loop
dbms_output.put_line('Hello:' || r.X);
end loop;
end;
/


Thanks to Flavio Casetta's "Annals of Oracle's Improbable Errors" :
http://oraclequirks.blogspot.com/200...d-default.html
Hi Gerard,

Thanks for the reply.

Not wanting to take anything away from Flavio but, yes, we do need to have
repeating StaffDetails tags. Can anyone help with this?

Surely ther is just some simple "a/b/c" qualification or syntax/switch?

Cheers Richard Maher

Reply With Quote
  #5  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: xmltable and namespaces - 02-04-2011 , 03:43 AM



declare
soap_resp varchar(32767);
resp sys.xmltype;
begin
soap_resp :=
'<GetStaffDetailsResponse'
Quote:
| ' xmlns="https://www.axby.com/staffQuery/">'
| '<GetStaffDetailsResult>'
| '<StaffDetails>'
| '<AuEduPersonPreferredGivenName>Bruce</
AuEduPersonPreferredGivenName>'
| '<AuEduPersonPreferredSurname>Coad</
AuEduPersonPreferredSurname>'
| '<EmployeeID>000715BC</EmployeeID>'
| '</StaffDetails>'
| '<StaffDetails>'
| '<AuEduPersonPreferredGivenName>Lazy</
AuEduPersonPreferredGivenName>'
| '<AuEduPersonPreferredSurname>Richard</
AuEduPersonPreferredSurname>'
| '<EmployeeID>000999ZZ</EmployeeID>'
| '</StaffDetails>'
| '</GetStaffDetailsResult>'
| '</GetStaffDetailsResponse>';
resp := xmltype.createxml(soap_resp);

for r in (
select
extractvalue(
value(Y),
'/StaffDetails/EmployeeID',
'xmlns="https://www.axby.com/staffQuery/"') X
from
table(
xmlsequence(
extract(
resp,
'/GetStaffDetailsResponse/GetStaffDetailsResult/
StaffDetails',
'xmlns="https://www.axby.com/staffQuery/"'
)
)
) Y
) loop
dbms_output.put_line('Hello:' || r.X);
end loop;
end;
/

Reply With Quote
  #6  
Old   
Richard Maher
 
Posts: n/a

Default Re: xmltable and namespaces - 02-04-2011 , 04:27 PM



"Gerard H. Pille" <ghpille (AT) hotmail (DOT) com> wrote

Quote:
declare
soap_resp varchar(32767);
resp sys.xmltype;
begin
soap_resp :=
'<GetStaffDetailsResponse'
|| ' xmlns="https://www.axby.com/staffQuery/">'
|| '<GetStaffDetailsResult>'
|| '<StaffDetails>'
|| '<AuEduPersonPreferredGivenName>Bruce</
AuEduPersonPreferredGivenName>'
|| '<AuEduPersonPreferredSurname>Coad</
AuEduPersonPreferredSurname>'
|| '<EmployeeID>000715BC</EmployeeID>'
|| '</StaffDetails>'
|| '<StaffDetails>'
|| '<AuEduPersonPreferredGivenName>Lazy</
AuEduPersonPreferredGivenName>'
|| '<AuEduPersonPreferredSurname>Richard</
AuEduPersonPreferredSurname>'
|| '<EmployeeID>000999ZZ</EmployeeID>'
|| '</StaffDetails>'
|| '</GetStaffDetailsResult>'
|| '</GetStaffDetailsResponse>';

resp := xmltype.createxml(soap_resp);

for r in (
select
extractvalue(
value(Y),
'/StaffDetails/EmployeeID',
'xmlns="https://www.axby.com/staffQuery/"') X
from
table(
xmlsequence(
extract(
resp,
'/GetStaffDetailsResponse/GetStaffDetailsResult/
StaffDetails',
'xmlns="https://www.axby.com/staffQuery/"'
)
)
) Y
) loop
dbms_output.put_line('Hello:' || r.X);
end loop;
end;
/
Now that looks good! I'll give it a go on Monday. Thanks Gerard.

Cheers Richard Maher

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.