what is the easyest way to serialize Document object?
I'm using JAXP 1.2 and DOM2.0 (parser is Xerces 2.2.1).
It gives me this exception:
java.io.NotSerializableException: org.apache.crimson.tree.XmlDocument
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1330)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1302)
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at test.Test.<init>(Test.java:70)
at test.Test.main(Test.java:108)
It appears you are trying to use object serialization on an XML DOM.
Why don't you serialize it as XML, isn't that the whole idea?
Look at the javax.xml.transform package
--
WBB
author: Cocoon 2 Programming, web publishing with XML and Java
http://www.lanw.com/books/cocoonbook/default.htm
Hmmm, it looks like XmlDocument is not serializable!
I think using JSX (google should bring it up) would be
the easiest solution (it works the same as Java's normal
serialization, but doesn't require that classes implement
the "Serializable" (ie the problem above).
However, JSX will output all this in XML - which
seems ironic, although it will work fne ;-)
BTW: if you really want to serialize the *contents* of the
Document object, rather than serialize the object graph
itself, you probably want to the "serialize()" method, that
it part of DOM. If so, probably an XML group is a
better place to ask (I don't know where it is off the top
of my head).
HTH
Cheers,
Brendan
Actually, "serializing" XML in a binary form with Java serialization
would be considerably slower and produce a larger file than putting it
back into XML, or loading XML into classes.
XML's very fast to read and write.
--
<a href="http://kuoi.asui.uidaho.edu/~kamikaze/"> Mark Hughes </a>
"We remain convinced that this is the best defensive posture to adopt in
order to minimize casualties when the Great Old Ones return from beyond
the stars to eat our brains." -Charlie Stross, _The Concrete Jungle_