Search in sources :

Example 1 with KXmlSerializer

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());
}
Also used : StringWriter(java.io.StringWriter) KXmlSerializer(org.kxml2.io.KXmlSerializer) XmlSerializer(org.xmlpull.v1.XmlSerializer) KXmlSerializer(org.kxml2.io.KXmlSerializer)

Example 2 with KXmlSerializer

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);
}
Also used : StringWriter(java.io.StringWriter) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) KXmlSerializer(org.kxml2.io.KXmlSerializer) XmlSerializer(org.xmlpull.v1.XmlSerializer) KXmlSerializer(org.kxml2.io.KXmlSerializer)

Example 3 with KXmlSerializer

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;
    }
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KXmlSerializer(org.kxml2.io.KXmlSerializer) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with KXmlSerializer

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;
}
Also used : DataOutputStream(java.io.DataOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KXmlSerializer(org.kxml2.io.KXmlSerializer) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with KXmlSerializer

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;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) KXmlSerializer(org.kxml2.io.KXmlSerializer) XmlSerializer(org.xmlpull.v1.XmlSerializer) KXmlSerializer(org.kxml2.io.KXmlSerializer)

Aggregations

KXmlSerializer (org.kxml2.io.KXmlSerializer)11 StringWriter (java.io.StringWriter)5 XmlSerializer (org.xmlpull.v1.XmlSerializer)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 IOException (java.io.IOException)3 Element (org.kxml2.kdom.Element)3 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Document (org.kxml2.kdom.Document)2 MediaFile (org.opendatakit.briefcase.util.ServerFetcher.MediaFile)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 RandomAccessFile (java.io.RandomAccessFile)1 Writer (java.io.Writer)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1