How to create XML with multiple levels of depth using Castor?

I know how to creat an XML file using Castor's Marshaller.marshal(obj, file) method (where obj stores the person detail, and file specifis the name of xml file). but the xml created is only 1 level, as shown below:

<?xml version="1.0" encoding="UTF-8"?>
      <address>123 Foo Street</address>
      <name>Bob Harris</name>

does anyone know how to create xml file with more levels, for example,

<?xml version="1.0" encoding="UTF-8"?>
                  <home_address>123 Foo Street</home_address>
                            <work_address>456 Bar Street</work_address>
      <name>Bob Harris</name>

Is it possible to use castor methods? if not, what other methods are there?


Who is Participating?
For the schema generator look at:
Basically you create an XML schema that describe the XML structure you are looking for and
then you run this tool with the given schema as input. The tool will generate the Java objects
for you (like Person and Address). Those object will have marshall and unmarshall functions that you
can use.

This link describe how to use XML mapping file
to provide more infomation to the castor marshelling/unmarshalling framework regarding your objects.

You should use one or the other.
You can do that by either generate your java classes (that you want to marshel) using castor schema generator
(and make your schema have the required levels) or defing your own xml mapping which will use person and address classes.
tombomanAuthor Commented:
Hi aozarov,

Can you describe the steps in detail? or do you know any website that shows this in detail?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.