Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Creation

 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I need to create a XML file on a servlet and then send it to the user. As this XML file can be very big (150Mb in some cases), what will be the best package to create it? Can javax.xml.stream handle it?

Thanks
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the file have to be so large? It sounds like you should use FTP to send the file rather than HTTP.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You certainly want some sort of output stream writing approach.

If this was my problem I would probably end up with a lot of print() statements which would be similar in terms of coding effort to using an XMLStreamWriter from the javax.xml.stream package.

What is the source of the data? In some cases, a pipeline toolkit may exist that would be directly applicable.

Bill
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

First and in response to James Clark, the file has to be large as it must contain the accounts information from a entire year. With all the needed information, it can be a huge file.

Now, regarding the creation of this file, I've decided to use a XMLStreamWriter, but I'm having here some problems. The main one is that the created file doesn't have the new line at the end and the xml file created is not formatted!

How can I make XMLStreamWriter to add a new line at the end of a element and make it format the output?

Thanks
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First and in response to James Clark, the file has to be large as it must contain the accounts information from a entire year. With all the needed information, it can be a huge file.


So, the user will click on a HTML link on a web page and the application will return this massive (150 MB) file in response. Is this correct?

Is this an Internet application or Intranet? After the user clicks on the link, how long will they have to wait for the response?



How can I make XMLStreamWriter to add a new line at the end of a element and make it format the output?


To format a XML file, you can create an XSL stylesheet to apply a format.

Since, you are concerned about formatting, do you expect this huge (150 MB) file to be read by a human?
[ July 01, 2008: Message edited by: James Clark ]
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

Yes, the user click a HTML link and receives the file. The application will work on a Intranet mainly, but it can also work over the Internet, but on those cases, the file will be a smaller one for sure. Also this 150Mb will be maybe a 1% case as the rest of them will be around 10 to 20Mb and with today connections this is like 5m download or even less.

Concerning the formating, I need it to read the file when making the development as I must check if nothing is missing and if everything is in place cause rigth now I don't have any data to put on the file and I'm only preparing the structure of it, so that when I receive the missing data, everything is in place and it's a 5 minute change on the code to add it.

I have a "xsd" file. How can I validate my XML file on the fly with the XMLStreamWriter?

Thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I validate my XML file on the fly with the XMLStreamWriter?


You can't - XMLStreamWriter only takes care of certain formatting - see the JavaDocs. It is up to you the programmer to make sure that start Elements have matching end Elements, etc etc. However, once you get this right for a single account record it should be correct for the entire file.

If you want any extra formatting line feeds you will have to write them to the output stream yourself. The XML specification does not require line breaks or other human readable formatting.

Bill
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:

If you want any extra formatting line feeds you will have to write them to the output stream yourself. The XML specification does not require line breaks or other human readable formatting.

Bill


Is there any other package and class that I can use and that will allow the auto formatting of the output?

Thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look into the "pipeline" toolkit I suggest earlier?

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic