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

Posted on 2005-04-17
Medium Priority
Last Modified: 2010-03-31
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?


Question by:tomboman
  • 2
LVL 15

Expert Comment

ID: 13803798
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.

Author Comment

ID: 13803817
Hi aozarov,

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

LVL 15

Accepted Solution

aozarov earned 500 total points
ID: 13803827
For the schema generator look at: http://www.castor.org/sourcegen.html
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 http://www.castor.org/xml-mapping.html 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.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

750 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