This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML Creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Creation" Watch "XML Creation" New topic
Author

XML Creation

Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
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

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Oct 24, 2002
Posts: 126
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

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Oct 24, 2002
Posts: 126
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Oct 24, 2002
Posts: 126
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
Did you look into the "pipeline" toolkit I suggest earlier?

Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XML Creation
 
Similar Threads
How to display XML documents using JSP?
JSP on the fly from XML
Must I create new file when client invoke soap method?
Help to insert characters
create DTD