Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XML Forest,XML Concat

Posted on 2009-07-14
17
Medium Priority
?
1,677 Views
Last Modified: 2012-05-07
Hi,

I have a wo function in oracle which returns XML type.

Sample XML From First Function
<customer>
<Fname>testFname</Fname>
<Lname>testLname</Lname>
</customer>

Sample XML From Second Function
<PostalAddress>
<address1>testaddress1</Fname>
<address2>testaddress2</Lname>
</PostalAddress>

I need to add postal address tag under customer tag.

Oupt Put

<Customers>
<customer>
<Fname>testFname</Fname>
<Lname>testLname</Lname>
<PostalAddress>
<address1>testaddress1</Fname>
<address2>testaddress2</Lname>
</PostalAddress>
</customer>
</Customers>

how to achieve this ?

Regards,
Chandan N




--Presenly i am using the below code
--but not able to generate the required XMl structure
SELECT  XMLElement("Customers",function1(),Function2()) INTO xml_temp FROM dual;
please find the attachment for the present code

Open in new window

query.txt
0
Comment
Question by:Chandan_Gowda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
17 Comments
 
LVL 48

Expert Comment

by:schwertner
ID: 24849170
Curious what will give you
SELECT  XMLElement("Customers",function1() || Function2()) INTO xml_temp FROM dual;
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 24850001
you don't want to use xmelement or any of the xml aggregation functions,
you are simply inserting nodes within other nodes.

use INSERTCHILDXML to do that...


select INSERTCHILDXML(
           xmltype('<Customers></Customers>'),
           '/Customers',
           'customer',
           INSERTCHILDXML(function1, '/customer', 'PostalAddress', function2)
       ) from dual
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24852430
Thanks!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Author Comment

by:Chandan_Gowda
ID: 24877023
Finally by some R & D,made this working
find the attachment for  solution

select insertChildXML(xml_cust, '/Customer', 'PostalAddress', xml_postal, null) into xml_temp 
from dual;

Open in new window

0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24878264
that appears to be what I posted except you have removed the outer <Customers>  node
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24878355
Thanks!
0
 
LVL 7

Author Comment

by:Chandan_Gowda
ID: 24921849
i resolved it myself....Please refund my points back
0
 
LVL 7

Author Comment

by:Chandan_Gowda
ID: 24921885
The core part is to get the nodes;sdstuber solution didnt had that part correct.That is the main element of the solution.How can this comment be considered as a correct one if it is not working,I had to do lot of work around to get the solution,Only the syntax is correct,But the logic is not correct,
Before accepcting the solution forcibly,The solution has to be checked for its logic.
Please refund my points back.
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24924637
I will suggest to delete the whole question.

Also please regard the will of the Asker.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24931088
Chandan_Gowda,

Sorry, I was gone on vacation for several days and just got back to see the comments.

I didn't have the your functions to work with so I wrote my own that returned the xml presented in the original question (except I corrected the address1 and address2 closing tags)
The post I made above is exactly what I tested with and it returned exactly the xml you requested.

The query I posted returns the requested xml, if this does not work, please post what did not work about it.
I've attached the functions from my test case.

<Customers>
  <customer>
    <Fname>testFname</Fname>
    <Lname>testLname</Lname>
    <PostalAddress>
      <address1>testaddress1</address1>
      <address2>testaddress2</address2>
    </PostalAddress>
  </customer>
</Customers>

 
create or replace function function1 return xmltype
is
begin
  return xmltype('<customer>
<Fname>testFname</Fname>
<Lname>testLname</Lname>
</customer>');
end;
 
--  Note, address1 and address2  closing tags have been corrected, from the original question's sample data.
create or replace function function2 return xmltype
is
begin
  return xmltype('<PostalAddress>
<address1>testaddress1</address1>    
<address2>testaddress2</address2>
</PostalAddress>');
end;

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question