?
Solved

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

Posted on 2005-04-17
5
Medium Priority
?
275 Views
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"?>
<person>
      <ssn>222-222-2222</ssn>
      <address>123 Foo Street</address>
      <work-phone>(123)123-1234</work-phone>
      <home-phone>(123)123-1234</home-phone>
      <email>bob@harris.org</email>
      <name>Bob Harris</name>
</person>

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

<?xml version="1.0" encoding="UTF-8"?>
<person>
                <address>
                  <home_address>123 Foo Street</home_address>
                            <work_address>456 Bar Street</work_address>
                </address>
                <phone>
                  <work_phone>(123)123-1234</work_phone>
                  <home_phone>(123)123-1234</home_phone>
                </phone>
      <email>bob@harris.org</email>
      <name>Bob Harris</name>
</person>


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

thansk


0
Comment
Question by:tomboman
  • 2
3 Comments
 
LVL 15

Expert Comment

by:aozarov
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.
0
 

Author Comment

by:tomboman
ID: 13803817
Hi aozarov,

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

Thanks.
0
 
LVL 15

Accepted Solution

by:
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.
0

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