Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XML document serialization

8 views
Skip to first unread message

Darije Ramljak

unread,
Dec 13, 2002, 3:02:19 AM12/13/02
to
hi,

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)


William Brogden

unread,
Dec 13, 2002, 8:02:18 AM12/13/02
to
"Darije Ramljak" <darije....@etk.ericsson.se> wrote in message
news:atc3m8$len$1...@newstoo.ericsson.se...

> hi,
>
> 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)


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

Brendan Macmillan

unread,
Dec 14, 2002, 2:22:41 AM12/14/02
to
> 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


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


Mark 'Kamikaze' Hughes

unread,
Dec 14, 2002, 12:18:05 PM12/14/02
to
14 Dec 2002 18:22:41 +1100, Brendan Macmillan <br...@mail.csse.monash.edu.au>:

>> 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
> 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 ;-)

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_

0 new messages