convert an array to xml

i want to know how to convert a static array to an xml file
[66 byte] By [soumayaa] at [2007-11-27 1:45:47]
# 1

if you know that nothing else is going to be in that xml, array is of strings or something else that can be represented as strings, and that the receiver will be able to parse that xml you can just do:

FileOutputStream fout = new FileOutputStream("bilbo.xml");

fout.println("<array>");

for(int i=0; i<array.size(); i++)

{

fout.println("><element>"+array[i]+"</element>");

}

fout.println("</array>");

Message was edited by:

ethical_anarhist

ethical_anarhista at 2007-7-12 1:06:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
You need to be more specific, I presume that you want to have column headers used as node or attribute?Do you have a dtd or xsd?Pete_j
Pete_ja at 2007-7-12 1:06:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

my array is made of java beans

the java bean is called PageContent, it is made of

*media_vasp

*media_id

*media_name

*media_price

*media_size

*media_URL

i want to return this array in an xml file by the means of a servlet

meaning that i want to return the xml in the http response of the servlet.

soumayaa at 2007-7-12 1:06:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
The first step is to decide on the format of the XML file. You need to decide things like the names of elements, whether data is to be put into text or into attributes, and so on. This is called "design" and it should always be done before you start programming.
DrClapa at 2007-7-12 1:06:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Knowing what you want to have in XML and how to access DOC components is a good beginning. Having xsd is definitely helpful.

It sounds however that you may be a bit away from that, with bean you can query them and get their content and attribute values. There are number of paths to go from here, for nice exposition see:

http://builder.com.com/5100-6371_14-1044810.html?tag=search

Pete_j

Message was edited by:

Pete_j

Pete_ja at 2007-7-12 1:06:33 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...