简体   繁体   English

将oracle数据库转换为xml

[英]Convert oracle database to xml

I have a relational database in Oracle.我在 Oracle 中有一个关系数据库。

I would like to convert this database to xml.我想将此数据库转换为 xml。 For example, I have a table in Oracle like the following one: (that's a very simple example,in my database there is no table like that)例如,我在 Oracle 中有一个表,如下所示:(这是一个非常简单的例子,在我的数据库中没有这样的表)

 TABLE: PERSON
 ----------------------------------------------------
 ID | NAME | DESCRIPTION
 ----------------------------------------------------
 1  | George | Employee
 2  | Mary   | Student
 3  | Joe    | Employee
-------------------------------------------------------

The xml output would be xml 输出将是

<?xml version="1.0" encoding="UTF-8"?>
<persons>
  <person>
    <ID>1</ID>
    <NAME>George</NAME>
    <DESCRIPTION>Employee</DESCRIPTION>
  </person>
  <person>
    <ID>2</ID>
    <NAME>Mary</NAME>
    <DESCRIPTION>Student</DESCRIPTION>
  </person>
  <person>
    <ID>3</ID>
    <NAME>Joe</NAME>
    <DESCRIPTION>Employee</DESCRIPTION>
  </person>
</persons>

Which is the best way to make the conversion?进行转换的最佳方法是什么?

1) Shall i do it on my own? 1)要我自己做吗?

a) Create my own xsd schema based on the database's design b) Create my own mechanism that is going to create xml documents automatically by selecting and joining the tables. a)根据数据库的设计创建我自己的 xsd 模式b)创建我自己的机制,该机制将通过选择和加入表来自动创建 xml 文档。

OR或者

2) Shall i use an online tool in order to make that conversion? 2)我应该使用在线工具来进行转换吗? And if it is yes, which are the best ones for that conversion?如果是的话,哪些是最适合这种转换的?

Thanks, in advance提前致谢

Directly by the oracle engine:直接通过oracle引擎:

select xmlelement( "PERSON", xmlforest( id, name, description ) ) 
from PERSON;    

Oracle provides built-in functionality for this: Oracle 为此提供了内置功能:

with v_data as (
  select 1 as id, 'George' as name, 'Employee' as description from dual union all
  select 2 as id, 'Mary' as name, 'Student' as description from dual union all
  select 3 as id, 'Joe' as name, 'Employee' as description from dual)
select 
  xmlelement("Persons", 
    xmlagg(
      xmlelement("Person", 
        xmlforest(e.id, e.name, e.description)
      ) 
     order by id)
  ) as "Person list"
from v_data e

Depending on you real data, you might want to use an incremental approach using DBMS_XMLGEN or similar, see Oracle XML DB Developer's Guide根据您的真实数据,您可能希望使用 DBMS_XMLGEN 或类似方法使用增量方法,请参阅Oracle XML DB Developer's Guide

If you are using any programming languages like Java, you can use any Object Relational Mapping framework like JPA/Hibernate/etc.如果您使用任何编程语言,如 Java,则可以使用任何对象关系映射框架,如 JPA/Hibernate/等。 and serialize mapped objects to xml using JAXB or XStream or any other xml serializing APIs.并使用 JAXB 或 XStream 或任何其他 xml 序列化 API 将映射对象序列化为 xml。

If you would like to do manually, tools like Altova MapForce also be used if you can afford如果您想手动完成,如果您负担得起,也可以使用 Altova MapForce 等工具

http://www.altova.com/mapforce/database-mapping.html http://www.altova.com/mapforce/database-mapping.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM