Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-21-2007, 02:06 PM
Member
 
Join Date: Apr 2007
Location: India
Posts: 2
ims6674 is on a distinguished road
Help in XML
Hi,

I am new to XML and as my first assignment I got a task to generate a XML file. I am able to generate it with a lengthy procedure, however I want it to generate in generic way.

Could you please help me?

Thanks,
Imran.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-21-2007, 02:49 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Hi Imran,

Can you give more details about your problem/solution. What do you mean with lengthy procedure?

If you can describe your problem more, we can help. You can paste your source code and XML sample too if they will help us understand your problem.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-21-2007, 08:13 PM
Member
 
Join Date: Apr 2007
Location: Indiana
Posts: 84
pegitha is on a distinguished road
Send a message via Skype™ to pegitha
Jaxb is a great package for generating xml files. I put some sample code below. But, it depends on exactly how you are obtaining the data to put into your xml file. If you do not have the data anyplace you are going to have to enter it, maybe in a database , then use jaxb to format it into xml files. Anyway, maybe you can explain in detail what you are doing so we can offer specific help.
Here is some generic jaxb code:
Code:
JAXBContext jaxbContext = JAXBContext.newInstance(MyBean.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty("jaxb.formatted.output",new Boolean(true)); //gather data method would be here, fill in your beans File xml = new File(baseDir, "myXMLFIle.xml"); marshaller.marshal( listOfBeans, new FileOutputStream(xml));
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-23-2007, 09:13 AM
Member
 
Join Date: Apr 2007
Location: India
Posts: 2
ims6674 is on a distinguished road
Hi,
Thanks for your reply.

I have to generate a xml file which includes 45-50 tag elements depending upon the user's input i.e. dynamically. Few of them are having child nodes.

I am able to generate this file by writting each and every tag element, adding its attribute if present then adding the text node.

I want to ask, Is there any way so that I can generalize my code by
calling any method so that to reduce the code length?

I was also able to write one method, to which I am passing the tag element and its text node value, however it fails if that tag element is having some child nodes.

Could you please find some solution to this?

Thanks,
Imran.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-24-2007, 01:26 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Hi Imran,

I did not use XStream, but as far as i see you can create an object, set its fields based on user input and serialize it to XML with XStream. I guess it will have less numbers of lines and easier to maintain compared to manual serialization.

As far as i see, it is also possible to do this with JAXB. Check following tech tip:

Object Serialization with the JAXB Libraries and Revisiting Timers with Enterprise Beans Tech Tips

Last edited by levent : 04-24-2007 at 01:29 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 04:56 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org