I just checked over this old email from you, about XMLEncoder (see below)
In it, you say that XMLEncoder cannot work, because much information is lost.
However, I've been reading up on XMLEncoder, and a key part of the design is
that it deliberately omits any information that is part of the default settings.
Thus, if you have an empty document (with all its attributes set to default
values), XMLEncoder will give you a *very* short description of it! This might
be the case for the example below - was it an empty document? Or was
there extra information it in, that you had changed from the default (eg: by
adding text, or setting values on it?)
The way to test this is simply to use XMLDecoder on the file, and see if it
works to re-create the original document or not!
On the other hand, in my review of the XMLEncoder source code, I note that there
are lots of comments suggesting that there are several un-fixed bugs -
so it is quite possible that it is failing on your specific document!
PS: The problem with JSX *seems* to be the Validation mechanism. This works
for JSX in JDK1.3, but the code is not yet properly hooked up for JDK1.4.
The patch that Bill Reynolds created deals with other issues in JDK1.4, but
not this particular one.
> I have tried java.beans.XMLEncoder and XMLDecoder to serialize the
> Document object, but they can not work correctly.
> My code list here:
> //XMLEncoder xle = new XMLEncoder(
> // new BufferedOutputStream(
> // new
> // xle.close();
> - the XML generated by java.beans.XMLEncoder under 1.4, list here:
> <?xml version="1.0" encoding="UTF-8"?>
> <java version="1.4.0_01" class="java.beans.XMLDecoder">
> <object class="javax.swing.text.DefaultStyledDocument">
> <void property="documentProperties">
> <void method="put">
> <object class="java.awt.font.TextAttribute" field="RUN_DIRECTION"/>
> Obviously, the result lost many important information.
> And I build my project by using Jbuilder, as Mike Goldwater said
> that "Make sure your jar is
> built using *all* the .class files in Brendan's jar." I think what I
> shoud do is make sure to add this line im my program "import JSX.*;".
> Is it right?
> Thank you very much.
> Hi BFcat,
> > I use JSX18.104.22.168 and JSX22.214.171.124 to serialize a Document from
> > JTextPane(in my program it is call m_monitor). The JSX's ObjOut wirte
> > the Document to a XML file successfly under JDK1.3.1 and JDK1.4.01.
> > But JSX's ObjIn can not read the XML(which is output under JDK1.4.01)
> > outputed by ObjOut under JDK1.4.01. If I run the program under
> > JDK1.3.1, every things seem work well.
> > So, I guess there may be a bug, could anyone give me some advice?
> Thanks a lot for checking out the possibilities before posting, and for
> the stacktrace and your source code.
> Unfortunately, there does seem to be a problem with some inner classes
> in JSX under 1.4 - so Document probably has one. In fact, it the
> problem could even be this one: javax.swing.text.StyleContext$NamedStyle
> This is a serious bug, that will be fixed; but it probably won't be
> fixed for a while... but to help, could I ask you to please post:
> - the XML generated by JSX under 1.3, and
> - the XML generated by JSX under 1.4,
> (I see that you are not trying to move the XML between
> 1.3 and 1.4, but the XML *might* reveal part of the problem).
> The other thing, is have you tried java.beans.XMLEncoder and XMLDecoder?