Search in sources :

Example 91 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer 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 92 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project robovm by robovm.

the class KxmlSerializerTest method testInvalidCharactersInText.

public void testInvalidCharactersInText() throws IOException {
    XmlSerializer serializer = newSerializer();
    serializer.startTag(NAMESPACE, "root");
    for (int ch = 0; ch <= 0xffff; ++ch) {
        final String s = Character.toString((char) ch);
        if (isValidXmlCodePoint(ch)) {
            serializer.text("a" + s + "b");
        } else {
            try {
                serializer.text("a" + s + "b");
                fail(s);
            } catch (IllegalArgumentException expected) {
            }
        }
    }
    serializer.endTag(NAMESPACE, "root");
}
Also used : XmlSerializer(org.xmlpull.v1.XmlSerializer) KXmlSerializer(org.kxml2.io.KXmlSerializer)

Example 93 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project robovm by robovm.

the class KxmlSerializerTest method testInvalidCharactersInAttributeValues.

public void testInvalidCharactersInAttributeValues() throws IOException {
    XmlSerializer serializer = newSerializer();
    serializer.startTag(NAMESPACE, "root");
    for (int ch = 0; ch <= 0xffff; ++ch) {
        final String s = Character.toString((char) ch);
        if (isValidXmlCodePoint(ch)) {
            serializer.attribute(NAMESPACE, "a", "a" + s + "b");
        } else {
            try {
                serializer.attribute(NAMESPACE, "a", "a" + s + "b");
                fail(s);
            } catch (IllegalArgumentException expected) {
            }
        }
    }
    serializer.endTag(NAMESPACE, "root");
}
Also used : XmlSerializer(org.xmlpull.v1.XmlSerializer) KXmlSerializer(org.kxml2.io.KXmlSerializer)

Example 94 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer 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 95 with XmlSerializer

use of org.xmlpull.v1.XmlSerializer in project robovm by robovm.

the class KxmlSerializerTest method testInvalidCharactersInCdataSections.

public void testInvalidCharactersInCdataSections() throws IOException {
    XmlSerializer serializer = newSerializer();
    serializer.startTag(NAMESPACE, "root");
    for (int ch = 0; ch <= 0xffff; ++ch) {
        final String s = Character.toString((char) ch);
        if (isValidXmlCodePoint(ch)) {
            serializer.cdsect("a" + s + "b");
        } else {
            try {
                serializer.cdsect("a" + s + "b");
                fail(s);
            } catch (IllegalArgumentException expected) {
            }
        }
    }
    serializer.endTag(NAMESPACE, "root");
}
Also used : XmlSerializer(org.xmlpull.v1.XmlSerializer) KXmlSerializer(org.kxml2.io.KXmlSerializer)

Aggregations

XmlSerializer (org.xmlpull.v1.XmlSerializer)268 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)156 IOException (java.io.IOException)151 FileOutputStream (java.io.FileOutputStream)144 BufferedOutputStream (java.io.BufferedOutputStream)57 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 AtomicFile (android.util.AtomicFile)39 RemoteException (android.os.RemoteException)29 File (java.io.File)26 FileNotFoundException (java.io.FileNotFoundException)26 StringWriter (java.io.StringWriter)26 Map (java.util.Map)23 ErrnoException (android.system.ErrnoException)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)15 JournaledFile (com.android.internal.util.JournaledFile)15 UserInfo (android.content.pm.UserInfo)9 HashMap (java.util.HashMap)9 SendIntentException (android.content.IntentSender.SendIntentException)8 PackageParserException (android.content.pm.PackageParser.PackageParserException)8