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());
}
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");
}
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");
}
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);
}
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");
}
Aggregations