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!

The new line doesn't work when generating xml

User_RFKSXMay 3 2021

Hi,
let's suppose to have the table

create table mytable
(val1 number(5),
val2 varchar2(10));

insert into mytable values (1,'XXX');

and asked to generate the following XML

<ns1:head>
<ns1:val1>1</val1>
<ns1:val2>XXX</val2>
</ns1:head>

It's quite simple by running

select xmlelement("head",
xmlelement("val1",val1).extract('/*'),
xmlelement("val2",val2).extract('/*')
).extract('/*')
from mytable;

and to get

<head>
<val1>1</val1>
<val2>XXX</val2>
</head>

The problem is that if I try to do that way but for getting each node with "ns1:" in front of every tag

select xmlelement("ns1:head",
xmlelement("ns1:val1",val1).extract('/*'),
xmlelement("ns1:val2",val2).extract('/*')
).extract('/*')
from mytable;

I get an ORA-31011: XML parsing failed

Maybe I dont' konw how exactly the .extract('/*') works and in my case the "ns1:" could fails

Oracle version 10g

Thanks in advance!
Mark

This post has been answered by BluShadow on May 4 2021
Jump to Answer
Comments
Post Details
Added on May 3 2021
8 comments
1,487 views