本文整理汇总了Java中org.xmlpull.v1.XmlSerializer.setOutput方法的典型用法代码示例。如果您正苦于以下问题:Java XmlSerializer.setOutput方法的具体用法?Java XmlSerializer.setOutput怎么用?Java XmlSerializer.setOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmlpull.v1.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.setOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePublicXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void generatePublicXml(ResPackage pkg, Directory out,
XmlSerializer serial) throws AndrolibException {
try {
OutputStream outStream = out.getFileOutput("values/public.xml");
serial.setOutput(outStream, null);
serial.startDocument(null, null);
serial.startTag(null, "resources");
for (ResResSpec spec : pkg.listResSpecs()) {
serial.startTag(null, "public");
serial.attribute(null, "type", spec.getType().getName());
serial.attribute(null, "name", spec.getName());
serial.attribute(null, "id", String.format("0x%08x", spec.getId().id));
serial.endTag(null, "public");
}
serial.endTag(null, "resources");
serial.endDocument();
serial.flush();
outStream.close();
} catch (IOException | DirectoryException ex) {
throw new AndrolibException("Could not generate public.xml file", ex);
}
}
示例2: writeUserLocked
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void writeUserLocked(VUserInfo userInfo) {
FileOutputStream fos = null;
AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + ".xml"));
try {
fos = userFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(userInfo.id));
serializer.attribute(null, ATTR_SERIAL_NO, Integer.toString(userInfo.serialNumber));
serializer.attribute(null, ATTR_FLAGS, Integer.toString(userInfo.flags));
serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime));
serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME,
Long.toString(userInfo.lastLoggedInTime));
if (userInfo.iconPath != null) {
serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath);
}
if (userInfo.partial) {
serializer.attribute(null, ATTR_PARTIAL, "true");
}
serializer.startTag(null, TAG_NAME);
serializer.text(userInfo.name);
serializer.endTag(null, TAG_NAME);
serializer.endTag(null, TAG_USER);
serializer.endDocument();
userFile.finishWrite(fos);
} catch (Exception ioe) {
VLog.e(LOG_TAG, "Error writing user info " + userInfo.id + "\n" + ioe);
userFile.failWrite(fos);
}
}
示例3: save
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的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 org.xmlpull.v1.XmlSerializer; //导入方法依赖的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: escape
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* @param text The text to escape.
* @return
*/
public static String escape(String text) {
try {
StringWriter sw = new StringWriter();
XmlSerializer serializer = PARSER_FACTORY.newSerializer();
serializer.setOutput(sw);
serializer.text(text).flush();
return sw.toString();
} catch(XmlPullParserException | IOException e) {
// Should never get here.
throw new IllegalStateException("Unable to build/use XmlSerializer.");
}
}
示例6: getXmlSerializer
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private XmlSerializer getXmlSerializer(ByteArrayOutputStream os)
throws BlocklySerializerException
{
XmlSerializer serializer;
try {
xmlPullParserFactory.setNamespaceAware(true);
serializer = xmlPullParserFactory.newSerializer();
serializer.setOutput(os, null);
return serializer;
} catch (XmlPullParserException | IOException e) {
throw new BlocklySerializerException(e);
}
}
示例7: getXmlSerializer
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private XmlSerializer getXmlSerializer(ByteArrayOutputStream os)
throws BlocklySerializerException
{
XmlSerializer serializer;
try {
mXmlPullParserFactory.setNamespaceAware(true);
serializer = mXmlPullParserFactory.newSerializer();
serializer.setOutput(os, null);
return serializer;
} catch (XmlPullParserException | IOException e) {
throw new BlocklySerializerException(e);
}
}
示例8: writeUserListLocked
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void writeUserListLocked() {
FileOutputStream fos = null;
AtomicFile userListFile = new AtomicFile(mUserListFile);
try {
fos = userListFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_USERS);
serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber));
serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion));
for (int i = 0; i < mUsers.size(); i++) {
VUserInfo user = mUsers.valueAt(i);
serializer.startTag(null, TAG_USER);
serializer.attribute(null, ATTR_ID, Integer.toString(user.id));
serializer.endTag(null, TAG_USER);
}
serializer.endTag(null, TAG_USERS);
serializer.endDocument();
userListFile.finishWrite(fos);
} catch (Exception e) {
userListFile.failWrite(fos);
VLog.e(LOG_TAG, "Error writing user list");
}
}
示例9: initAndStartDocument
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的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;
}
示例10: getAllSMS
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的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();
}
}
示例11: createChangesetXmlBody
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的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();
}
示例12: updateNodeXmlBody
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的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();
}
示例13: createNodeXmlBody
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的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();
}
示例14: doInBackground
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
public Void doInBackground(Object... args) {
List<HistoricalRecord> historicalRecords = args[0];
String hostoryFileName = args[1];
try {
FileOutputStream fos = ActivityChooserModel.this.mContext.openFileOutput(hostoryFileName, 0);
XmlSerializer serializer = Xml.newSerializer();
try {
serializer.setOutput(fos, null);
serializer.startDocument("UTF-8", Boolean.valueOf(true));
serializer.startTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORDS);
int recordCount = historicalRecords.size();
for (int i = 0; i < recordCount; i++) {
HistoricalRecord record = (HistoricalRecord) historicalRecords.remove(0);
serializer.startTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORD);
serializer.attribute(null, "activity", record.activity.flattenToString());
serializer.attribute(null, ActivityChooserModel.ATTRIBUTE_TIME, String.valueOf(record.time));
serializer.attribute(null, "weight", String.valueOf(record.weight));
serializer.endTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORD);
}
serializer.endTag(null, ActivityChooserModel.TAG_HISTORICAL_RECORDS);
serializer.endDocument();
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
}
}
} catch (IllegalArgumentException iae) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + ActivityChooserModel.this.mHistoryFileName, iae);
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e2) {
}
}
} catch (IllegalStateException ise) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + ActivityChooserModel.this.mHistoryFileName, ise);
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e3) {
}
}
} catch (IOException ioe) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + ActivityChooserModel.this.mHistoryFileName, ioe);
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e4) {
}
}
} catch (Throwable th) {
ActivityChooserModel.this.mCanReadHistoricalData = true;
if (fos != null) {
try {
fos.close();
} catch (IOException e5) {
}
}
}
return null;
} catch (FileNotFoundException fnfe) {
Log.e(ActivityChooserModel.LOG_TAG, "Error writing historical recrod file: " + hostoryFileName, fnfe);
return null;
}
}
示例15: captureElement
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* Serializes the current element and all child nodes as a String.
* @param parser The parser to pull from.
* @return The composed element string.
* @throws XmlPullParserException
* @throws IOException
*/
public static String captureElement(XmlPullParser parser)
throws XmlPullParserException, IOException
{
int event = parser.getEventType();
if (event != XmlPullParser.START_TAG) {
throw new XmlPullParserException("Expected call to begin at START_TAG");
}
int depth = 0;
StringWriter sw = new StringWriter();
XmlSerializer serializer = PARSER_FACTORY.newSerializer();
serializer.setOutput(sw);
String namespace, prefix;
while (event != XmlPullParser.END_DOCUMENT) {
switch (event) {
case XmlPullParser.START_TAG:
++depth;
namespace = parser.getNamespace();
prefix = parser.getPrefix();
if (namespace != null && prefix != null) {
serializer.setPrefix(prefix, namespace);
}
serializer.startTag(namespace, parser.getName());
int attrCount = parser.getAttributeCount();
for (int i = 0; i < attrCount; ++i) {
namespace = parser.getAttributeNamespace(i);
prefix = parser.getAttributePrefix(i);
if (namespace != null && prefix != null) {
serializer.setPrefix(prefix, namespace);
}
serializer.attribute(namespace, parser.getAttributeName(i),
parser.getAttributeValue(i));
}
break;
case XmlPullParser.TEXT:
case XmlPullParser.IGNORABLE_WHITESPACE:
serializer.text(parser.getText());
break;
case XmlPullParser.CDSECT:
serializer.cdsect(parser.getText());
break;
case XmlPullParser.END_TAG:
namespace = parser.getNamespace();
if (namespace != null) {
serializer.setPrefix(parser.getPrefix(), namespace);
}
serializer.endTag(namespace, parser.getName());
--depth;
break;
}
if (depth <= 0) {
serializer.flush();
return sw.toString();
}
event = parser.next();
}
throw new IOException("Unexpected end of document.");
}