XML Bean

S

Shinya Koizumi

Can i serialize xml to object using XML Bean?
Each record stored in Oracle database as xml type and
I want to serialize this xml to java beans so that I can easily edit

this record. XML Bean is the tool to go for it?
 
J

jwagenleitner

Shinya said:
Can i serialize xml to object using XML Bean?
Each record stored in Oracle database as xml type and
I want to serialize this xml to java beans so that I can easily edit

this record. XML Bean is the tool to go for it?

You can if you are referring to XMLBeans (http://xmlbeans.apache.org).
You'll need an XML Schema file in order to have XMLBeans generate the
required Java classes. XMLBeans comes with a tool (inst2xsd) that will
enable you to turn an xml file into a schema if you don't have a schema
file already.

XMLBeans is my favorite java to xml binding tool. I find it very clean
to work with the generate classes and methods. With it you always deal
with the objects that are meaningful and this keeps your code clean and
easier to read and maintain in my opinion. One of the things I dislike
about JAXB is that is makes you deal with objects outside those related
to your schema types.

John
 
S

sk

The thing is that our schema will be generated when I connect to the oracle.
I believe the class has to be generated at the development time, right?

Shinya
 
J

jwagenleitner

sk said:
The thing is that our schema will be generated when I connect to the oracle.
I believe the class has to be generated at the development time, right?

Shinya

Only way I know how to map xml to java objects is to know ahead of time
the schema or at least have an instance of the xml document in order to
create a schema. While you may not have the schema you should at least
know the structure of the xml you are going to parse. From an example
you can generate a schema and from that schema you can generate the
required java objects. You do this at development time so that in your
program XMLBeans (or Castor or JAXB) has some objects to marshal the
xml data into.

John
 
S

sk

Our xml saved in the Oracle's xml type field is going to be like the
following:
the structure will be saved at the different table.

<meta12345>
<meta789456>Scientific XML Data</meta789456>
<meta789457>
<meta789458>Scientific XML Data<meta789458>
<meta789458>Scientific XML Data<meta789458>
<meta789457/>
<meta789459>Scientific XML Data<meta789459>
</meta12345>

The schema (xsd ) generated when connecting the database for the firstime
will be like this

<xs:element name="meta123456">
<xs:complextype>
<xs:sequence>
<xs:element name="meta789457" />
<xs:complextype>
<xs:element ref="meta789458" minOccurs="1"
minOccurs="5">
</xs:complextype>
<xs:restriction base="xs:string"/>
</xs:element>
<xs:element ref="meta789459" />
</xs:sequence>
</xs:complextype>
</xs:element>

<xs:element name="meta789458">
<xs:simpletype>
<xs:restriction base="xs:integer" >
</xs:simpletype>
</xs:element>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top