我試圖做到這一點使用XmlSerializer的純文本格式的XML:添加使用的XmlSerializer
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE tv SYSTEM "xmltv.dtd">
<tv>
<channel id="com.example.android.sampletvinput.2-1" repeat-programs="true">
<display-name>Google</display-name>
<display-number>2-1</display-number>
<icon src="http://storage.googleapis.com/android-tv/images/google.png" />
</channel>
我已經得到多數所有的,除了
<!DOCTYPE tv SYSTEM "xmltv.dtd">
如果我嘗試添加它使用serializer.text,它只是返回<!DOCTYPE tv SYSTEM "xmltv.dtd">
我該如何處理這個問題以獲得一個完全相同的副本?
代碼:
private static String xmlCreate() {
XmlSerializer serializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
try {
serializer.setOutput(writer);
serializer.startDocument("UTF-8", false);
serializer.startTag("","<!DOCTYPE tv SYSTEM \"xmltv.dtd\">");
serializer.startTag("", "tv");
//serializer.setPrefix("id", "0000");
serializer.startTag("", "channel");
serializer.attribute("", "id", "0000");
serializer.attribute("", "repeat-programs", "true");
serializer.startTag("", "display-name");
serializer.text("GOOGLE");
serializer.endTag("", "display-name");
serializer.startTag("", "display-number");
serializer.text("1111");
serializer.endTag("", "display-number");
serializer.endTag("", "channel");
serializer.endTag("", "tv");
serializer.endDocument();
Log.d(TAG,"DOCUMENT: " + writer.toString());
return writer.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}