|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
alleged chars at begining. error read xml from file.Hi,
I am using XStream for the first time. saving to file works fine but loading from file gives the following error: [Fatal Error] :1:1: Content is not allowed in prolog. I checked and there is no BOM in the file. I wrote a test program to show what I am doing and to make sure it still happens (and it does). import com.thoughtworks.xstream.InitializationException; import com.thoughtworks.xstream.XStreamException; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; import java.io.FileWriter; import java.io.IOException; public class Streame { public int i=0; } class Pilot { public static void main(String[] args) { //to(); from(); } private static void to() { try{ XStream xstream = new XStream( new DomDriver() ); FileWriter fw = new FileWriter("aaa.xml"); xstream.toXML( new Streame(), fw ); } catch(IOException e) { System.out.format("to xml.\n%s", e.getMessage() ); } catch(InitializationException e) { System.out.format("to xml.\n%s", e.getMessage() ); } catch(XStreamException e) { System.out.format("to xml.\n%s", e.getMessage() ); } } private static void from() { try{ XStream xstream = new XStream( new DomDriver() ); Streame s = (Streame)xstream.fromXML("aaa.xml"); System.out.format("%d\n", s.i ); } catch(InitializationException e) { System.out.format("from xml. %s\n", e.getMessage() ); } catch(XStreamException e) { System.out.format("from xml. %s\n", e.getMessage() ); } } } if I use libxpp3 instead, I get the following error: : only whitespace content allowed before start tag and not b (position: START_DOCUMENT seen b... @1:1) Here is the generated xml: <Streame> <i>0</i> </Streame> I also tried adding the tag: <?xml version=\"1.0\" encoding=\"utf-8\"?> at the begining but that did not help either. btw I am working on ubuntu. could it be some encoding issue? thanks. |
|
|
Re: alleged chars at begining. error read xml from file.Hi Guy,
Guy Kroizman wrote: > Hi, > > I am using XStream for the first time. saving to file works fine but > loading from file gives the following error: > [Fatal Error] :1:1: Content is not allowed in prolog. > > I checked and there is no BOM in the file. Sorry, this is exactly the error that occurs with a BOM in the file. > I wrote a test program to show what I am doing and to make sure it still > happens (and it does). [snip] > * > if I use libxpp3 instead, I get the following error: > : only whitespace content allowed before start tag and not b (position: > START_DOCUMENT seen b... @1:1) Yes, because the Xpp3 parser cannot process a BOM also. > Here is the generated xml: > <Streame> > <i>0</i> > </Streame> > > I also tried adding the tag: > <?xml version=\"1.0\" encoding=\"utf-8\"?> > at the begining but that did not help either. > > btw I am working on ubuntu. could it be some encoding issue? Believe me, there's a BOM! Call ~$ od -c aaa.xml and look what it reports for the first bytes. - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: alleged chars at begining. error read xml from file.od -c aaa.xml
0000000 < S t r e a m e > \n < i > 0 0000020 < / i > \n < / S t r e a m e > 0000037
On Tue, Sep 15, 2009 at 7:55 PM, Jörg Schaible <joerg.schaible@...> wrote: Hi Guy, |
|
|
Re: Re: alleged chars at begining. error read xml from file.Hi Guy,
Guy Kroizman wrote at Dienstag, 15. September 2009 20:06: > od -c aaa.xml > 0000000 < S t r e a m e > \n < i > 0 > 0000020 < / i > \n < / S t r e a m e > > 0000037 this looks good. However, keep in mind some editors add a BOM if you add an XML header to a file. AFAICS we can ignore your platform, personally I'm running Gentoo. Actually I have no idea, why this should fail. But the error does not occur in XStream in first place, because the underlaying XML parsers fail themselves. You already tried the W3C DOM parser and the Xpp3 parser with the different drivers. This is no coincidence - especially since both parsers fail with the first character of the provided data. - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: Re: alleged chars at begining. error read xml from file.Problem solved!
Only god knows what gave me the stupid idea that I can pass a file path to the XStream::fromXml function. (: Sorry for wasting your time. G'Day
On Wed, Sep 16, 2009 at 3:52 PM, Jörg Schaible <joerg.schaible@...> wrote: Hi Guy, |
|
|
Re: Re: Re: alleged chars at begining. error read xml from file.Guy Kroizman wrote:
> Problem solved! > Only god knows what gave me the stupid idea that I can pass a file path to > the XStream::fromXml function. (: > Sorry for wasting your time. Shit happens ... hehehe ;-) - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |