dbTalk Databases Forums  

Question about XML and Oracle.

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Question about XML and Oracle. in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John Peterson
 
Posts: n/a

Default Question about XML and Oracle. - 11-18-2010 , 02:30 PM






I'm not sure if this is the correct forum, but I'll give it a shot.

I'm using the Oracle built-in XML functions to format a result set into an
XML representation.

However, I can't quite figure out how to "wrap" my results with a
header/footer.

For example, I want my output to be:

<?xml version="1.0" encoding="UTF-8" ?>
<OuterElement>
<AllMyQueryResultsXML/>
</OuterElement>

I've successfully created a multi-row query that generates the
<AllMyQueryResultsXML>. But, I can't figure out how to get the final step
of wrapping those results in the version and <OuterElement> aspects.

I know I can use XMLRoot for the version aspect. But the <OuterElement>
eludes me. I've tried doing stuff like:

select xmltype("<OuterElement>") from dual
union all
....MyMultiRowQueryThatReturnsXMLTYPE...
union all
select xmltype("</OuterElement>") from dual

But that doesn't work, because XMLTYPE expects well-formed XML. I've tried
variations on the theme with XMLSERIALIZE and XMLCONCAT, but I can't seem to
get it to work.

Any help that anyone can provide would be *much* appreciated.

Thanks!

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

Default Re: Question about XML and Oracle. - 11-19-2010 , 11:30 AM






John Peterson wrote:
Quote:
I'm not sure if this is the correct forum, but I'll give it a shot.

I'm using the Oracle built-in XML functions to format a result set into
an XML representation.

However, I can't quite figure out how to "wrap" my results with a
header/footer.

For example, I want my output to be:

?xml version="1.0" encoding="UTF-8" ?
OuterElement
AllMyQueryResultsXML/
/OuterElement

I've successfully created a multi-row query that generates the
AllMyQueryResultsXML>. But, I can't figure out how to get the final
step of wrapping those results in the version and <OuterElement> aspects.

I know I can use XMLRoot for the version aspect. But the <OuterElement
eludes me. I've tried doing stuff like:

select xmltype("<OuterElement>") from dual
union all
...MyMultiRowQueryThatReturnsXMLTYPE...
union all
select xmltype("</OuterElement>") from dual

But that doesn't work, because XMLTYPE expects well-formed XML. I've
tried variations on the theme with XMLSERIALIZE and XMLCONCAT, but I
can't seem to get it to work.

Any help that anyone can provide would be *much* appreciated.

Thanks!


SELECT XMLROOT ( XMLElement("OuterElement",
"<AllMyQueryResultsXML/>"
), VERSION '1.0', STANDALONE YES)
AS "XMLROOT" FROM DUAL;

Reply With Quote
  #3  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: Question about XML and Oracle. - 11-19-2010 , 11:45 AM



On 18.11.2010 21:30, John Peterson wrote:
Quote:
I'm not sure if this is the correct forum, but I'll give it a shot.

I'm using the Oracle built-in XML functions to format a result set into
an XML representation.

However, I can't quite figure out how to "wrap" my results with a
header/footer.

For example, I want my output to be:

?xml version="1.0" encoding="UTF-8" ?
OuterElement
AllMyQueryResultsXML/
/OuterElement

I've successfully created a multi-row query that generates the
AllMyQueryResultsXML>. But, I can't figure out how to get the final
step of wrapping those results in the version and <OuterElement> aspects.

I know I can use XMLRoot for the version aspect. But the <OuterElement
eludes me. I've tried doing stuff like:

select xmltype("<OuterElement>") from dual
union all
....MyMultiRowQueryThatReturnsXMLTYPE...
union all
select xmltype("</OuterElement>") from dual

But that doesn't work, because XMLTYPE expects well-formed XML. I've
tried variations on the theme with XMLSERIALIZE and XMLCONCAT, but I
can't seem to get it to work.

Any help that anyone can provide would be *much* appreciated.

Thanks!


You may try something like this:

SQL> select xmlroot(
2 xmlelement("OuterElement",
3 xmltype(cursor(select loc from dept))
4 )
5 , version '1.0').extract('/') xml
6 from dual
7 /

XML
-------------------------
<?xml version="1.0"?>
<OuterElement>
<ROWSET>
<ROW>
<LOC>NEW YORK</LOC>
</ROW>
<ROW>
<LOC>DALLAS</LOC>
</ROW>
<ROW>
<LOC>CHICAGO</LOC>
</ROW>
<ROW>
<LOC>BOSTON</LOC>
</ROW>
</ROWSET>
</OuterElement>

where xmltype(cursor(...)) should represent your data like in
"MyMultiRowQueryThatReturnsXMLTYPE"
Note, that extract('/') is added only to make pretty print of produced
xml, it isn't necessary for your purpose.

Best regards

Maxim

Reply With Quote
  #4  
Old   
John Peterson
 
Posts: n/a

Default Re: Question about XML and Oracle. - 12-01-2010 , 12:03 PM



"Maxim Demenko" <mdemenko (AT) gmail (DOT) com> wrote

Quote:
On 18.11.2010 21:30, John Peterson wrote:
I'm not sure if this is the correct forum, but I'll give it a shot.

I'm using the Oracle built-in XML functions to format a result set into
an XML representation.

However, I can't quite figure out how to "wrap" my results with a
header/footer.

For example, I want my output to be:

?xml version="1.0" encoding="UTF-8" ?
OuterElement
AllMyQueryResultsXML/
/OuterElement

I've successfully created a multi-row query that generates the
AllMyQueryResultsXML>. But, I can't figure out how to get the final
step of wrapping those results in the version and <OuterElement> aspects.

I know I can use XMLRoot for the version aspect. But the <OuterElement
eludes me. I've tried doing stuff like:

select xmltype("<OuterElement>") from dual
union all
....MyMultiRowQueryThatReturnsXMLTYPE...
union all
select xmltype("</OuterElement>") from dual

But that doesn't work, because XMLTYPE expects well-formed XML. I've
tried variations on the theme with XMLSERIALIZE and XMLCONCAT, but I
can't seem to get it to work.

Any help that anyone can provide would be *much* appreciated.

Thanks!



You may try something like this:

SQL> select xmlroot(
2 xmlelement("OuterElement",
3 xmltype(cursor(select loc from dept))
4 )
5 , version '1.0').extract('/') xml
6 from dual
7 /

XML
-------------------------
?xml version="1.0"?
OuterElement
ROWSET
ROW
LOC>NEW YORK</LOC
/ROW
ROW
LOC>DALLAS</LOC
/ROW
ROW
LOC>CHICAGO</LOC
/ROW
ROW
LOC>BOSTON</LOC
/ROW
/ROWSET
/OuterElement

where xmltype(cursor(...)) should represent your data like in
"MyMultiRowQueryThatReturnsXMLTYPE"
Note, that extract('/') is added only to make pretty print of produced
xml, it isn't necessary for your purpose.

Best regards

Maxim
Dear Maxim,

Thanks so much for the tip! This seems to work great!

I wish there were some way to eliminate the embedded
<ROWSET><ROW><XMLRESULT> tags -- but I guess it's simple enough to
search/replace "after the fact".

The crux of what I was missing (I think) was that nifty "cursor" keyword.
Very interesting...

Thanks again!

Reply With Quote
  #5  
Old   
John Peterson
 
Posts: n/a

Default Re: Question about XML and Oracle. - 12-01-2010 , 12:04 PM



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

Quote:
John Peterson wrote:
I'm not sure if this is the correct forum, but I'll give it a shot.

I'm using the Oracle built-in XML functions to format a result set into
an XML representation.

However, I can't quite figure out how to "wrap" my results with a
header/footer.

For example, I want my output to be:

?xml version="1.0" encoding="UTF-8" ?
OuterElement
AllMyQueryResultsXML/
/OuterElement

I've successfully created a multi-row query that generates the
AllMyQueryResultsXML>. But, I can't figure out how to get the final
step of wrapping those results in the version and <OuterElement> aspects.

I know I can use XMLRoot for the version aspect. But the <OuterElement
eludes me. I've tried doing stuff like:

select xmltype("<OuterElement>") from dual
union all
...MyMultiRowQueryThatReturnsXMLTYPE...
union all
select xmltype("</OuterElement>") from dual

But that doesn't work, because XMLTYPE expects well-formed XML. I've
tried variations on the theme with XMLSERIALIZE and XMLCONCAT, but I
can't seem to get it to work.

Any help that anyone can provide would be *much* appreciated.

Thanks!



SELECT XMLROOT ( XMLElement("OuterElement",
"<AllMyQueryResultsXML/>"
), VERSION '1.0', STANDALONE YES)
AS "XMLROOT" FROM DUAL;


Thanks Gerald -- but I can't seem to figure out how to structure the query
inside of the outer query. Maxim's reply seems to be (sort of) working for
me, so I'll probably go that route.

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

Default Re: Question about XML and Oracle. - 12-02-2010 , 02:06 PM



John Peterson wrote:
Quote:
"Gerard H. Pille" <ghp (AT) skynet (DOT) be> wrote


SELECT XMLROOT ( XMLElement("OuterElement",
"<AllMyQueryResultsXML/>"
), VERSION '1.0', STANDALONE YES)
AS "XMLROOT" FROM DUAL;



Thanks Gerald -- but I can't seem to figure out how to structure the query inside of the outer
query. Maxim's reply seems to be (sort of) working for me, so I'll probably go that route.
Pourtant, c'est simple comme bonjour:


XMLROOT
--------------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" standalone="yes"?>
<OuterElement>
<Topic>
<TOPICID>1</TOPICID>
<TOPICDESC>This is the first topic</TOPICDESC>
<AREA>0</AREA>
</Topic>
<Topic>
<TOPICID>2</TOPICID>
<TOPICDESC>This is the second topic</TOPICDESC>
<AREA>0</AREA>
</Topic>
<Topic>
<TOPICID>3</TOPICID>
<TOPICDESC>This is the third topic</TOPICDESC>
<AREA>1</AREA>
</Topic>
<Topic>
<TOPICID>4</TOPICID>
<TOPICDESC>This is the fourth topic</TOPICDESC>
<AREA>1</AREA>
</Topic>
</OuterElement>


SQL> l
1 SELECT XMLROOT (
2 XMLElement(
3 "OuterElement",
4 xmlagg(
5 XMLElement(
6 "Topic",
7 xmlelement("TOPICID",TOPICID),
8 xmlelement("TOPICDESC",TOPICDESC),
9 xmlelement("AREA",AREA)
10 )
11 )
12 ), VERSION '1.0', STANDALONE YES)
13* AS "XMLROOT" FROM faq.topic

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.