Re: [Simple-support] carriage return
Brought to you by:
niallg
|
From: Hans <fis...@ya...> - 2012-05-03 20:57:55
|
Hi,
> I think this is down the the underlying parser. Simple does not parse
> the XML. Have you tried to use<![CDATA[ ]> blocks, use
> @Element(data=true).
>
yes i tried. The serialized string contains the \r in the CDATA block.
But after deserialisation the \r is still replaced by a \n.
I tried the same with java.beans.XMLEncoder/XMLDecoder.
After serializing the string contains instead of \r and
after deserializing it the string of interest contains \r !
See example code below.
So i tried to do the same with the previous simpleXML example.
But after deserializing the xml.getContent() string contains still the
character reference and not a \r
Any way to configure simpleXML ot the used parser to preserve the \r ?
package carriage_return;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class CarriageReturn2 {
public static class Xml {
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
public static void main(String[] args) throws Exception {
Xml xml = new Xml();
xml.setContent("Hello\rSimpleXML");
ByteArrayOutputStream baos = write(xml);
System.out.println(baos.toString());
xml = read(new ByteArrayInputStream(baos.toByteArray()));
System.out.println(xml.getContent().contains("\r"));
}
public static ByteArrayOutputStream write(Xml xml) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(baos);
encoder.writeObject(xml);
encoder.close();
return baos;
}
public static Xml read(ByteArrayInputStream bais) throws Exception {
XMLDecoder decoder = new XMLDecoder(bais);
Xml o = (Xml) decoder.readObject();
decoder.close();
return o;
}
}
|