use of org.kxml2.io.KXmlSerializer in project robovm by robovm.
the class KxmlSerializerTest method testWriteDocument.
public void testWriteDocument() throws Exception {
StringWriter stringWriter = new StringWriter();
XmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(stringWriter);
serializer.startDocument("UTF-8", null);
serializer.startTag(NAMESPACE, "foo");
serializer.attribute(NAMESPACE, "quux", "abc");
serializer.startTag(NAMESPACE, "bar");
serializer.endTag(NAMESPACE, "bar");
serializer.startTag(NAMESPACE, "baz");
serializer.endTag(NAMESPACE, "baz");
serializer.endTag(NAMESPACE, "foo");
serializer.endDocument();
assertXmlEquals("<foo quux=\"abc\"><bar /><baz /></foo>", stringWriter.toString());
}
use of org.kxml2.io.KXmlSerializer in project robovm by robovm.
the class KxmlSerializerTest method testCdataWithTerminatorInside.
public void testCdataWithTerminatorInside() throws Exception {
StringWriter writer = new StringWriter();
XmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(writer);
serializer.startDocument("UTF-8", null);
serializer.startTag(NAMESPACE, "p");
serializer.cdsect("a]]>b");
serializer.endTag(NAMESPACE, "p");
serializer.endDocument();
// Adjacent CDATA sections aren't merged, so let's stick them together ourselves...
Document doc = domOf(writer.toString());
NodeList children = doc.getFirstChild().getChildNodes();
String text = "";
for (int i = 0; i < children.getLength(); ++i) {
text += children.item(i).getNodeValue();
}
assertEquals("a]]>b", text);
}
use of org.kxml2.io.KXmlSerializer in project javarosa by opendatakit.
the class XFormSerializer method getUtfBytes.
public static byte[] getUtfBytes(Document doc) {
KXmlSerializer serializer = new KXmlSerializer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
Writer osw = new OutputStreamWriter(bos, "UTF-8");
serializer.setOutput(osw);
doc.write(serializer);
serializer.flush();
return bos.toByteArray();
} catch (Exception e) {
Std.printStack(e);
return null;
}
}
use of org.kxml2.io.KXmlSerializer in project javarosa by opendatakit.
the class XFormSerializer method elementToString.
public static String elementToString(Element e) {
KXmlSerializer serializer = new KXmlSerializer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
String s = null;
try {
serializer.setOutput(dos, null);
e.write(serializer);
serializer.flush();
s = new String(bos.toByteArray(), "UTF-8");
return s;
} catch (UnsupportedEncodingException uce) {
Std.printStack(uce);
} catch (Exception ex) {
Std.printStack(ex);
return null;
}
return null;
}
use of org.kxml2.io.KXmlSerializer in project robovm by robovm.
the class KxmlSerializerTest method newSerializer.
private static XmlSerializer newSerializer() throws IOException {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
XmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(bytesOut, "UTF-8");
serializer.startDocument("UTF-8", null);
return serializer;
}
Aggregations