help needed with xml

N

Nik

this is what I could make with the help of a java book:


public static void serialize(String filename)
{
try {
XMLEncoder o = new XMLEncoder( new FileOutputStream(filename));

o.writeObject("Today");
o.writeObject(new Date());
o.close();

} catch (FileNotFoundException e) {}
}


this code creates an XML file containing this:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_05" class="java.beans.XMLDecoder">
<string>Today</string>
<object class="java.util.Date">
<long>1114933156049</long>
</object>
</java>


so far it looks not bad but instead of the <string>, <long> etc. tags I
want to create own tags. the final XML should have this format:

<archive name="archive1">
<file name="xx">
<size>100</size>
<ext>jpg</ext>
</file>
</archive>


I did not really understand how I have to use DOM (I am kind of new to this)

any help is appreciated :)
 
A

Alan Krueger

Nik said:
so far it looks not bad but instead of the <string>, <long> etc. tags I
want to create own tags. the final XML should have this format:

<archive name="archive1">
<file name="xx">
<size>100</size>
<ext>jpg</ext>
</file>
</archive>

I did not really understand how I have to use DOM (I am kind of new to
this)

You're serializing objects to the XML format supported by Java
serialization. If you want to produce a specific XML format, you could
do something like this:

http://javaalmanac.com/egs/org.w3c.dom/AddNode.html
http://javaalmanac.com/egs/javax.xml.transform/WriteDom.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top