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
Solved

XML Forest,XML Concat

Posted on 2009-07-14
17
1,644 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
  • 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 500 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import and exporting Oracle Data with encrypted columns 4 48
Oracle dataguard 5 43
XSLT Display Label Name 1 27
Read XML values 8 41
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

792 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