本文整理汇总了Java中android.util.Xml.newSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java Xml.newSerializer方法的具体用法?Java Xml.newSerializer怎么用?Java Xml.newSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.Xml
的用法示例。
在下文中一共展示了Xml.newSerializer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTasksExport
import android.util.Xml; //导入方法依赖的package包/类
private void doTasksExport(String output) throws IOException {
File xmlFile = new File(output);
xmlFile.createNewFile();
FileOutputStream fos = new FileOutputStream(xmlFile);
xml = Xml.newSerializer();
xml.setOutput(fos, BackupConstants.XML_ENCODING);
xml.startDocument(null, null);
xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
xml.startTag(null, BackupConstants.ASTRID_TAG);
xml.attribute(null, BackupConstants.ASTRID_ATTR_VERSION,
Integer.toString(preferences.getLastSetVersion()));
xml.attribute(null, BackupConstants.ASTRID_ATTR_FORMAT,
Integer.toString(FORMAT));
serializeTasks();
serializeTagDatas();
xml.endTag(null, BackupConstants.ASTRID_TAG);
xml.endDocument();
xml.flush();
fos.close();
}
示例2: save
import android.util.Xml; //导入方法依赖的package包/类
/**
* Method that saves list of document into XML file
* @throws IOException
*/
@Override
public void save() throws IOException {
Log.d("DocManager","ActualSave");
File toWrite = new File(context.getFilesDir(), URI);
FileOutputStream fos = new FileOutputStream(toWrite);
XmlSerializer xmlSerializer = Xml.newSerializer();
xmlSerializer.setOutput(fos, "UTF-8");
xmlSerializer.startDocument(null, true);
xmlSerializer.startTag(null, "documentList");
for(int i=0; i < documents.size(); ++i){
xmlSerializer.startTag(null, "document");
addTag(xmlSerializer, "uri", documents.get(i).getUri());
addTag(xmlSerializer, "title", documents.get(i).getTitle());
addTag(xmlSerializer, "author", documents.get(i).getAuthor());
addTag(xmlSerializer, "importDate", String.valueOf(documents.get(i).getImportDate().getTime()));
addTag(xmlSerializer, "lastReadPosition", String.valueOf(documents.get(i).getLastReadPosition()));
Log.d("CicloFir",String.valueOf(documents.get(i).getLastReadPosition()));
//addTag(xmlSerializer, "length", String.valueOf(documents.get(i).getLength()));
// Insert list of bookmarks
for(int j=0; j < documents.get(i).getBookmark().size(); ++j){
addTag(xmlSerializer, "bmName", documents.get(i).getBookmark().get(j).getName());
addTag(xmlSerializer, "bmPosition", String.valueOf(documents.get(i).getBookmark().get(j).getIndex()));
}
xmlSerializer.endTag(null, "document");
}
xmlSerializer.endTag(null, "documentList");
xmlSerializer.endDocument();
xmlSerializer.flush();
fos.close();
}
示例3: save
import android.util.Xml; //导入方法依赖的package包/类
/***
* Public Method that save current application setting to XML file
* @throws IOException
*/
public void save() throws IOException {
//SettingManager systemSetts = new SettingManager();
TextSetting textSetts = (TextSetting) /*systemSetts.*/settings.get(0);
ArrayMap<String, String> textSpecs = textSetts.getSpecs();
ThemeSetting themeSetts = (ThemeSetting) /*systemSetts.*/settings.get(1);
ArrayMap<String, String> themeSpecs = themeSetts.getSpecs();
FattsSetting fattsSetts = (FattsSetting) /*systemSetts.*/settings.get(2);
ArrayMap<String, String> fattsSpecs = fattsSetts.getSpecs();
File toWrite = new File(context.getFilesDir(), context.getResources().getString(R.string.uri_setting));
FileOutputStream fos = new FileOutputStream(toWrite);
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(fos, "UTF-8");
serializer.startDocument(null, true);
//serializer.setFeature(FEATURE_PROCESS_NAMESPACES, false);
serializer.startTag(null, "settings");
serializer.startTag(null, "textsetting");
genTag(serializer, "size", textSpecs.get("size"));
genTag(serializer, "spacing", textSpecs.get("spacing"));
genTag(serializer, "lineSpacing", textSpecs.get("lineSpacing"));
serializer.endTag(null, "textsetting");
serializer.startTag(null, "themesetting");
genTag(serializer, "font", themeSpecs.get("originalFont"));
genTag(serializer, "palette", themeSpecs.get("palette"));
genTag(serializer, "highlight", themeSpecs.get("highlight"));
serializer.endTag(null, "themesetting");
serializer.startTag(null, "fattssetting");
genTag(serializer, "id", fattsSpecs.get("id"));
genTag(serializer, "language", fattsSpecs.get("language"));
genTag(serializer, "gender", fattsSpecs.get("gender"));
genTag(serializer, "speed", fattsSpecs.get("speed"));
serializer.endTag(null, "fattssetting");
serializer.endDocument();
serializer.flush();
fos.close();
}
示例4: writeToStream
import android.util.Xml; //导入方法依赖的package包/类
/**
* XML interface: procedure writes this list into the given stream
*/
public boolean writeToStream(OutputStream stream, String name)
{
try
{
final StringWriter writer = new StringWriter();
final XmlSerializer serializer = Xml.newSerializer();
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.setOutput(writer);
serializer.startDocument("UTF-8", true);
serializer.setPrefix(FormulaList.XML_PROP_MMT, FormulaList.XML_HTTP);
serializer.startTag(FormulaList.XML_NS, FormulaList.XML_MAIN_TAG);
serializer.startTag(FormulaList.XML_NS, XML_LIST_TAG);
documentSettings.writeToXml(serializer);
final ArrayList<FormulaBase> fList = formulaListView.getFormulas(FormulaBase.class);
for (FormulaBase f : fList)
{
final String term = f.getBaseType().toString().toLowerCase(Locale.ENGLISH);
serializer.startTag(FormulaList.XML_NS, term);
f.writeToXml(serializer, String.valueOf(f.getId()));
serializer.endTag(FormulaList.XML_NS, term);
}
serializer.endTag(FormulaList.XML_NS, XML_LIST_TAG);
serializer.endTag(FormulaList.XML_NS, FormulaList.XML_MAIN_TAG);
serializer.endDocument();
stream.write(writer.toString().getBytes());
return true;
}
catch (Exception e)
{
final String error = String.format(activity.getResources().getString(R.string.error_file_write), name);
Toast.makeText(activity, error, Toast.LENGTH_LONG).show();
}
return false;
}
示例5: initAndStartDocument
import android.util.Xml; //导入方法依赖的package包/类
private static XmlSerializer initAndStartDocument(Writer output)
throws IllegalArgumentException, IllegalStateException, IOException {
XmlSerializer serializer = Xml.newSerializer();
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.setOutput(output);
serializer.startDocument(StringUtils.CHARSET_UTF8.name(), Boolean.TRUE);
return serializer;
}
示例6: writeSvg
import android.util.Xml; //导入方法依赖的package包/类
private static CharSequence writeSvg(Context ctx, Vector vector) {
if (vector != null) {
try {
CharArrayWriter writer = new CharArrayWriter();
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(writer);
serializer.startTag(SVG_NAMESPACE, "svg");
serializer.attribute(SVG_NAMESPACE, "width",
String.format(Locale.US, "%f", vector.mWidth));
serializer.attribute(SVG_NAMESPACE, "height",
String.format(Locale.US, "%f", vector.mHeight));
serializer.attribute(SVG_NAMESPACE, "viewBox",
String.format(Locale.US, "0 0 %f %f", vector.mWidth, vector.mHeight));
for (Group group : vector.mGroups) {
serializeGroup(ctx, serializer, vector, group);
}
for (Path path : vector.mPaths) {
serializePath(ctx, serializer, path);
}
serializer.endTag(SVG_NAMESPACE, "svg");
serializer.endDocument();
serializer.flush();
return writer.toString();
} catch (Exception ex) {
Log.e(TAG, "Can't write svg xml", ex);
}
}
return null;
}
示例7: serialize
import android.util.Xml; //导入方法依赖的package包/类
@Override
public String serialize(List<SplashAdvEntity> books) throws Exception {
// XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
// XmlSerializer serializer = factory.newSerializer();
XmlSerializer serializer = Xml.newSerializer(); //由android.util.Xml创建一个XmlSerializer实例
StringWriter writer = new StringWriter();
serializer.setOutput(writer); //设置输出方向为writer
serializer.startDocument("UTF-8", true);
serializer.startTag("", "splashadvs");
for (SplashAdvEntity splashAdvEntity : books) {
serializer.startTag("", "splashadv");
serializer.startTag("", "content");
serializer.text(splashAdvEntity.content);
serializer.endTag("", "content");
serializer.startTag("", "isAlive");
serializer.text(splashAdvEntity.isAlive);
serializer.endTag("", "isAlive");
serializer.startTag("", "filePath");
if(TextUtils.isEmpty(splashAdvEntity.filePath)){
serializer.text("");
}else{
serializer.text(splashAdvEntity.filePath);
}
serializer.endTag("", "filePath");
serializer.startTag("", "isAlive");
serializer.text(splashAdvEntity.isAlive);
serializer.endTag("", "isAlive");
serializer.endTag("", "splashadv");
}
serializer.endTag("", "splashadvs");
serializer.endDocument();
return writer.toString();
}
示例8: parseToXml
import android.util.Xml; //导入方法依赖的package包/类
static boolean parseToXml(ApplicationList applications, OutputStream out) {
XmlSerializer serializer = Xml.newSerializer();
try {
serializer.setOutput(out, "UTF-8");
serializer.startTag(ns, "fdroid");
for (ApplicationDetails app : applications) {
serializer.startTag(ns, "application");
writeTag(serializer, ID, app.getPackageName());
writeTag(serializer, LAST_UPDATED, app.getLastUpdatedDateString());
writeTag(serializer, NAME, app.getName());
writeTag(serializer, DESCRIPTION, app.getDescription());
writeTag(serializer, ICON_URL, app.getIconUrl());
writeTag(serializer, SOURCE_URL, app.getSourceCodeUrl());
writeTag(serializer, WEB, app.getWebUrl());
serializer.endTag(ns, "application");
}
serializer.endTag(ns, "fdroid");
serializer.flush();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
示例9: nodeToXML
import android.util.Xml; //导入方法依赖的package包/类
private String nodeToXML(Node node) {
XmlSerializer serializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
try {
serializer.setOutput(writer);
serializer.startDocument("UTF-8", true);
nodeToXml(serializer, node);
serializer.endDocument();
return writer.toString();
} catch (IOException e) {
throw new RuntimeException(e); // TODO: do my own
}
}
示例10: getAllSMS
import android.util.Xml; //导入方法依赖的package包/类
/**
* 获取手机短信并保存到xml中
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_SMS"/>}</p>
*/
public static void getAllSMS() {
// 1.获取短信
// 1.1获取内容解析者
ContentResolver resolver = Utils.getApp().getContentResolver();
// 1.2获取内容提供者地址 sms,sms表的地址:null 不写
// 1.3获取查询路径
Uri uri = Uri.parse("content://sms");
// 1.4.查询操作
// projection : 查询的字段
// selection : 查询的条件
// selectionArgs : 查询条件的参数
// sortOrder : 排序
Cursor cursor = resolver.query(uri, new String[]{"address", "date", "type", "body"}, null, null, null);
// 设置最大进度
int count = cursor.getCount();//获取短信的个数
// 2.备份短信
// 2.1获取xml序列器
XmlSerializer xmlSerializer = Xml.newSerializer();
try {
// 2.2设置xml文件保存的路径
// os : 保存的位置
// encoding : 编码格式
xmlSerializer.setOutput(new FileOutputStream(new File("/mnt/sdcard/backupsms.xml")), "utf-8");
// 2.3设置头信息
// standalone : 是否独立保存
xmlSerializer.startDocument("utf-8", true);
// 2.4设置根标签
xmlSerializer.startTag(null, "smss");
// 1.5.解析cursor
while (cursor.moveToNext()) {
SystemClock.sleep(1000);
// 2.5设置短信的标签
xmlSerializer.startTag(null, "sms");
// 2.6设置文本内容的标签
xmlSerializer.startTag(null, "address");
String address = cursor.getString(0);
// 2.7设置文本内容
xmlSerializer.text(address);
xmlSerializer.endTag(null, "address");
xmlSerializer.startTag(null, "date");
String date = cursor.getString(1);
xmlSerializer.text(date);
xmlSerializer.endTag(null, "date");
xmlSerializer.startTag(null, "type");
String type = cursor.getString(2);
xmlSerializer.text(type);
xmlSerializer.endTag(null, "type");
xmlSerializer.startTag(null, "body");
String body = cursor.getString(3);
xmlSerializer.text(body);
xmlSerializer.endTag(null, "body");
xmlSerializer.endTag(null, "sms");
System.out.println("address:" + address + " date:" + date + " type:" + type + " body:" + body);
}
xmlSerializer.endTag(null, "smss");
xmlSerializer.endDocument();
// 2.8将数据刷新到文件中
xmlSerializer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: getAllSMS
import android.util.Xml; //导入方法依赖的package包/类
/**
* 获取手机短信并保存到xml中
* <p>需添加权限 {@code <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>}</p>
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_SMS"/>}</p>
*/
public static void getAllSMS() {
// 1.获取短信
// 1.1获取内容解析者
ContentResolver resolver = Utils.getContext().getContentResolver();
// 1.2获取内容提供者地址 sms,sms表的地址:null 不写
// 1.3获取查询路径
Uri uri = Uri.parse("content://sms");
// 1.4.查询操作
// projection : 查询的字段
// selection : 查询的条件
// selectionArgs : 查询条件的参数
// sortOrder : 排序
Cursor cursor = resolver.query(uri, new String[]{"address", "date", "type", "body"}, null, null, null);
// 设置最大进度
int count = cursor.getCount();//获取短信的个数
// 2.备份短信
// 2.1获取xml序列器
XmlSerializer xmlSerializer = Xml.newSerializer();
try {
// 2.2设置xml文件保存的路径
// os : 保存的位置
// encoding : 编码格式
xmlSerializer.setOutput(new FileOutputStream(new File("/mnt/sdcard/backupsms.xml")), "utf-8");
// 2.3设置头信息
// standalone : 是否独立保存
xmlSerializer.startDocument("utf-8", true);
// 2.4设置根标签
xmlSerializer.startTag(null, "smss");
// 1.5.解析cursor
while (cursor.moveToNext()) {
SystemClock.sleep(1000);
// 2.5设置短信的标签
xmlSerializer.startTag(null, "sms");
// 2.6设置文本内容的标签
xmlSerializer.startTag(null, "address");
String address = cursor.getString(0);
// 2.7设置文本内容
xmlSerializer.text(address);
xmlSerializer.endTag(null, "address");
xmlSerializer.startTag(null, "date");
String date = cursor.getString(1);
xmlSerializer.text(date);
xmlSerializer.endTag(null, "date");
xmlSerializer.startTag(null, "type");
String type = cursor.getString(2);
xmlSerializer.text(type);
xmlSerializer.endTag(null, "type");
xmlSerializer.startTag(null, "body");
String body = cursor.getString(3);
xmlSerializer.text(body);
xmlSerializer.endTag(null, "body");
xmlSerializer.endTag(null, "sms");
System.out.println("address:" + address + " date:" + date + " type:" + type + " body:" + body);
}
xmlSerializer.endTag(null, "smss");
xmlSerializer.endDocument();
// 2.8将数据刷新到文件中
xmlSerializer.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: createChangesetXmlBody
import android.util.Xml; //导入方法依赖的package包/类
public static String createChangesetXmlBody(Map<String, String> tags) throws Exception {
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
if (tags == null) return null;
/**
*
<osm>
<changeset>
<tag k="created_by" v="JOSM 1.61"/>
<tag k="comment" v="Just adding some streetnames"/>
...
</changeset>
...
</osm>
*/
xmlSerializer.setOutput(writer);
// start DOCUMENT
xmlSerializer.startDocument("UTF-8", true);
// open tag: <osm>
xmlSerializer.startTag("", "osm");
// open tag: <changeset>
xmlSerializer.startTag("", "changeset");
//create tags
for (Map.Entry<String, String> tag : tags.entrySet()) {
xmlSerializer.startTag("", "tag");
xmlSerializer.attribute("", "k", tag.getKey());
xmlSerializer.attribute("", "v", tag.getValue());
xmlSerializer.endTag("", "tag");
}
// close tag: </changeset>
xmlSerializer.endTag("", "changeset");
// close tag: </osm>
xmlSerializer.endTag("", "osm");
// end DOCUMENT
xmlSerializer.endDocument();
return writer.toString();
}
示例13: updateNodeXmlBody
import android.util.Xml; //导入方法依赖的package包/类
public static String updateNodeXmlBody(Map<String, String> tags, long nodeId, String changesetId, double lat, double lon, int versionNumber) throws Exception {
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
if (tags == null) return null;
/**
*
<osm>
<node id="..." changeset="12" lat="..." lon="..." version="12">
<tag k="note" v="Just a node"/>
...
</node>
</osm>
*/
xmlSerializer.setOutput(writer);
// start DOCUMENT
xmlSerializer.startDocument("UTF-8", true);
// open tag: <osm>
xmlSerializer.startTag("", "osm");
// open tag: <changeset>
xmlSerializer.startTag("", "node");
xmlSerializer.attribute("", "id", String.valueOf(nodeId));
xmlSerializer.attribute("", "changeset", changesetId);
xmlSerializer.attribute("", "lat", String.valueOf(lat));
xmlSerializer.attribute("", "lon", String.valueOf(lon));
xmlSerializer.attribute("", "version", String.valueOf(versionNumber));
//create tags
for (Map.Entry<String, String> tag : tags.entrySet()) {
xmlSerializer.startTag("", "tag");
xmlSerializer.attribute("", "k", tag.getKey());
xmlSerializer.attribute("", "v", tag.getValue());
xmlSerializer.endTag("", "tag");
}
// close tag: </changeset>
xmlSerializer.endTag("", "node");
// close tag: </osm>
xmlSerializer.endTag("", "osm");
// end DOCUMENT
xmlSerializer.endDocument();
return writer.toString();
}
示例14: createNodeXmlBody
import android.util.Xml; //导入方法依赖的package包/类
public static String createNodeXmlBody(Map<String, String> tags, String changesetId, double lat, double lon) throws Exception {
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
if (tags == null) return null;
/**
*
<osm>
<node changeset="12" lat="..." lon="...">
<tag k="note" v="Just a node"/>
...
</node>
</osm>
*/
xmlSerializer.setOutput(writer);
// start DOCUMENT
xmlSerializer.startDocument("UTF-8", true);
// open tag: <osm>
xmlSerializer.startTag("", "osm");
// open tag: <changeset>
xmlSerializer.startTag("", "node");
xmlSerializer.attribute("", "changeset", changesetId);
xmlSerializer.attribute("", "lat", String.valueOf(lat));
xmlSerializer.attribute("", "lon", String.valueOf(lon));
//create tags
for (Map.Entry<String, String> tag : tags.entrySet()) {
xmlSerializer.startTag("", "tag");
xmlSerializer.attribute("", "k", tag.getKey());
xmlSerializer.attribute("", "v", tag.getValue());
xmlSerializer.endTag("", "tag");
}
// close tag: </changeset>
xmlSerializer.endTag("", "node");
// close tag: </osm>
xmlSerializer.endTag("", "osm");
// end DOCUMENT
xmlSerializer.endDocument();
return writer.toString();
}
示例15: xmlExport
import android.util.Xml; //导入方法依赖的package包/类
private void xmlExport(OutputStream out) throws IOException {
XmlSerializer serializer = Xml.newSerializer();
serializer.setOutput(out, "UTF-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, "netguard");
serializer.startTag(null, "application");
xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer);
serializer.endTag(null, "application");
serializer.startTag(null, "wifi");
xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "wifi");
serializer.startTag(null, "mobile");
xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "mobile");
serializer.startTag(null, "screen_wifi");
xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "screen_wifi");
serializer.startTag(null, "screen_other");
xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "screen_other");
serializer.startTag(null, "roaming");
xmlExport(getSharedPreferences("roaming", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "roaming");
serializer.startTag(null, "lockdown");
xmlExport(getSharedPreferences("lockdown", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "lockdown");
serializer.startTag(null, "apply");
xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "apply");
serializer.startTag(null, "notify");
xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer);
serializer.endTag(null, "notify");
serializer.startTag(null, "filter");
filterExport(serializer);
serializer.endTag(null, "filter");
serializer.startTag(null, "forward");
forwardExport(serializer);
serializer.endTag(null, "forward");
serializer.endTag(null, "netguard");
serializer.endDocument();
serializer.flush();
}