Solved

Convert Oracle data into XML document

Posted on 2016-11-09
2
85 Views
Last Modified: 2016-11-18
Hi Experts

I need to create a generic stored procedure which will take table name as input parameter and create xml file with below format. Xml file name should be table name and I've never done this before. Could you please help?

I tried few methods in Oracle but the output is not coming as expected.

<?xml version="1.0" encoding="UTF-8"?>
<MessageData>
      <Category>NewSubmission</Category>
      <TimeStamp>2016-07-22T12:11:00Z</TimeStamp>
      <ProdID>1234567890</ProdID>
</MessageData>
<Submission>
      <ReportingPeriod>2015-12-31</ReportingPeriod>      
      <Replacement>
            <MessageRef>12345678902016082313392REP</MessageRef>
            <ReplacedMessageRef>12345678902016072212110NEW</ReplacedMessageRef>
      </Replacement>
</Submission>
<Person>
      <FirstName>a</FirstName>
      <LastName>a</LastName>
      <Address>
      <City>a</City>
      <CountryCode>AF</CountryCode>
      <ResCountryCode>AF</ResCountryCode>
      </Address>
</Person>
0
Comment
Question by:Ram Karthik
[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
2 Comments
 
LVL 32

Expert Comment

by:awking00
ID: 41880533
Can you show the table structures and the data that would be used to produce your example xml file?
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 41880551
It looks like that data would come from different tables.  Do you have a one-to-many relation in there?

You sample XML you posted is also incorrect.  There is no root node.

Generating the XML is pretty easy.  I would suggest looking at the XML functions in SQL.

Here is the MessageData part of your XML:
/*
drop table tab1 purge;
create table tab1(category varchar2(20), time_stamp timestamp, prodid number);

insert into tab1 values('NewSubmission',to_timestamp('2016-07-22 12:11:00','YYYY-MM-DD HH24:MI:SS'),1234667890);
commit;
*/

select xmlelement("MessageData",
	xmlforest(
		category as "Category",
		to_char(time_stamp,'YYYY-MM-DD"T"HH24:MI:SS"Z"') as "TimeStamp",
		prodid as "ProdId"
	)
)
from tab1
/

Open in new window


If you can provide more detail about your tables, we can probably provide an expanded example.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

707 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