本文整理匯總了Java中org.xmlpull.v1.XmlSerializer.text方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlSerializer.text方法的具體用法?Java XmlSerializer.text怎麽用?Java XmlSerializer.text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.xmlpull.v1.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.text方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serializeToResValuesXml
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
@Override
public void serializeToResValuesXml(XmlSerializer serializer,
ResResource res) throws IOException, AndrolibException {
serializer.startTag(null, "plurals");
serializer.attribute(null, "name", res.getResSpec().getName());
for (int i = 0; i < mItems.length; i++) {
ResScalarValue item = mItems[i];
if (item == null) {
continue;
}
ResScalarValue rawValue = item;
serializer.startTag(null, "item");
serializer.attribute(null, "quantity", QUANTITY_MAP[i]);
serializer.text(ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(item.encodeAsResXmlValue()));
serializer.endTag(null, "item");
}
serializer.endTag(null, "plurals");
}
示例2: serializeToResValuesXml
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
@Override
public void serializeToResValuesXml(XmlSerializer serializer,
ResResource res) throws IOException, AndrolibException {
String type = getType();
type = (type == null ? "" : type + "-") + "array";
serializer.startTag(null, type);
serializer.attribute(null, "name", res.getResSpec().getName());
// lets check if we need to add formatted="false" to this array
for (int i = 0; i < mItems.length; i++) {
if (mItems[i].hasMultipleNonPositionalSubstitutions()) {
serializer.attribute(null, "formatted", "false");
break;
}
}
// add <item>'s
for (int i = 0; i < mItems.length; i++) {
serializer.startTag(null, "item");
serializer.text(mItems[i].encodeAsResXmlNonEscapedItemValue());
serializer.endTag(null, "item");
}
serializer.endTag(null, type);
}
示例3: 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);
}
}
示例4: writeElement
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
private static void writeElement(XmlSerializer serializer, String elementName, String value)
throws IllegalArgumentException, IllegalStateException, IOException {
if (value != null) {
serializer.startTag(null, elementName);
serializer.text(value);
serializer.endTag(null, elementName);
}
}
示例5: writeByteArrayXml
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
/**
* Flatten a byte[] into an XmlSerializer. The list can later be read back
* with readThisByteArrayXml().
*
* @param val The byte array to be flattened.
* @param name Name attribute to include with this array's tag, or null for
* none.
* @param out XmlSerializer to write the array into.
*
* @see #writeMapXml
* @see #writeValueXml
*/
public static final void writeByteArrayXml(byte[] val, String name,
XmlSerializer out)
throws XmlPullParserException, java.io.IOException {
if (val == null) {
out.startTag(null, "null");
out.endTag(null, "null");
return;
}
out.startTag(null, "byte-array");
if (name != null) {
out.attribute(null, "name", name);
}
final int N = val.length;
out.attribute(null, "num", Integer.toString(N));
StringBuilder sb = new StringBuilder(val.length*2);
for (int i=0; i<N; i++) {
int b = val[i];
int h = (b >> 4) & 0x0f;
sb.append((char)(h >= 10 ? ('a'+h-10) : ('0'+h)));
h = b & 0x0f;
sb.append((char)(h >= 10 ? ('a'+h-10) : ('0'+h)));
}
out.text(sb.toString());
out.endTag(null, "byte-array");
}
示例6: writeSimpleElement
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
public static void writeSimpleElement(XmlSerializer var0, String var1, String var2, String var3) throws IOException, XmlPullParserException {
if(var2 == null) {
throw new XmlPullParserException("name for element can not be null");
} else {
var0.startTag(var1, var2);
if(var3 == null) {
var0.attribute("http://www.w3.org/2001/XMLSchema-instance", "nil", "true");
} else {
var0.text(var3);
}
var0.endTag(var1, var2);
}
}
示例7: serialize
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
/**
* Writes information about the editable parts of the field as XML.
*
* @param serializer The XmlSerializer to write to.
*
* @throws IOException
*/
public void serialize(XmlSerializer serializer) throws IOException {
if (mType == TYPE_LABEL || mType == TYPE_IMAGE) {
return;
}
serializer.startTag(null, "field").attribute(null, "name", mName);
serializer.text(getSerializedValue());
serializer.endTag(null, "field");
}
示例8: serialize
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
@Override
public void serialize(XmlSerializer serializer) throws IOException {
serializer.startTag("", "mutation");
serializer.attribute("", "attr", mAttrib);
serializer.text(mText);
serializer.endTag("", "mutation");
}
示例9: writeIdentity
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
private static void writeIdentity(XmlSerializer serializer, String accountUuid, String identity,
Map<String, Object> prefs) throws IOException {
serializer.startTag(null, IDENTITY_ELEMENT);
String prefix = accountUuid + ".";
String suffix = "." + identity;
// Write name belonging to the identity
String name = (String) prefs.get(prefix + Account.IDENTITY_NAME_KEY + suffix);
serializer.startTag(null, NAME_ELEMENT);
serializer.text(name);
serializer.endTag(null, NAME_ELEMENT);
// Write email address belonging to the identity
String email = (String) prefs.get(prefix + Account.IDENTITY_EMAIL_KEY + suffix);
serializer.startTag(null, EMAIL_ELEMENT);
serializer.text(email);
serializer.endTag(null, EMAIL_ELEMENT);
// Write identity description
String description = (String) prefs.get(prefix + Account.IDENTITY_DESCRIPTION_KEY + suffix);
if (description != null) {
serializer.startTag(null, DESCRIPTION_ELEMENT);
serializer.text(description);
serializer.endTag(null, DESCRIPTION_ELEMENT);
}
// Write identity settings
serializer.startTag(null, SETTINGS_ELEMENT);
for (Map.Entry<String, Object> entry : prefs.entrySet()) {
String key = entry.getKey();
String valueString = entry.getValue().toString();
String[] comps = key.split("\\.");
if (comps.length < 3) {
// Skip non-identity config entries
continue;
}
String keyUuid = comps[0];
String identityKey = comps[1];
String identityIndex = comps[2];
if (!keyUuid.equals(accountUuid) || !identityIndex.equals(identity)) {
// Skip entries that belong to another identity
continue;
}
TreeMap<Integer, SettingsDescription> versionedSetting = IdentitySettings.SETTINGS.get(identityKey);
if (versionedSetting != null) {
Integer highestVersion = versionedSetting.lastKey();
SettingsDescription setting = versionedSetting.get(highestVersion);
if (setting != null) {
// Only write settings that have an entry in IdentitySettings.SETTINGS
try {
writeKeyAndPrettyValueFromSetting(serializer, identityKey, setting, valueString);
} catch (InvalidSettingValueException e) {
Timber.w("Identity setting \"%s\" has invalid value \"%s\" in preference storage. " +
"This shouldn't happen!", identityKey, valueString);
}
}
}
}
serializer.endTag(null, SETTINGS_ELEMENT);
serializer.endTag(null, IDENTITY_ELEMENT);
}
示例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: writeValueXml
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
/**
* Flatten an object's value into an XmlSerializer. The value can later
* be read back with readThisValueXml().
*
* Currently supported value types are: null, String, Integer, Long,
* Float, Double Boolean, Map, List.
*
* @param v The object to be flattened.
* @param name Name attribute to include with this value's tag, or null
* for none.
* @param out XmlSerializer to write the object into.
*
* @see #writeMapXml
* @see #writeListXml
* @see #readValueXml
*/
public static final void writeValueXml(Object v, String name, XmlSerializer out)
throws XmlPullParserException, java.io.IOException
{
String typeStr;
if (v == null) {
out.startTag(null, "null");
if (name != null) {
out.attribute(null, "name", name);
}
out.endTag(null, "null");
return;
} else if (v instanceof String) {
out.startTag(null, "string");
if (name != null) {
out.attribute(null, "name", name);
}
out.text(v.toString());
out.endTag(null, "string");
return;
} else if (v instanceof Integer) {
typeStr = "int";
} else if (v instanceof Long) {
typeStr = "long";
} else if (v instanceof Float) {
typeStr = "float";
} else if (v instanceof Double) {
typeStr = "double";
} else if (v instanceof Boolean) {
typeStr = "boolean";
} else if (v instanceof byte[]) {
writeByteArrayXml((byte[])v, name, out);
return;
} else if (v instanceof int[]) {
writeIntArrayXml((int[])v, name, out);
return;
} else if (v instanceof Map) {
writeMapXml((Map)v, name, out);
return;
} else if (v instanceof List) {
writeListXml((List)v, name, out);
return;
} else if (v instanceof Set) {
writeSetXml((Set)v, name, out);
return;
} else if (v instanceof CharSequence) {
// XXX This is to allow us to at least write something if
// we encounter styled text... but it means we will drop all
// of the styling information. :(
out.startTag(null, "string");
if (name != null) {
out.attribute(null, "name", name);
}
out.text(v.toString());
out.endTag(null, "string");
return;
} else {
throw new RuntimeException("writeValueXml: unable to write value " + v);
}
out.startTag(null, typeStr);
if (name != null) {
out.attribute(null, "name", name);
}
out.attribute(null, "value", v.toString());
out.endTag(null, typeStr);
}
示例12: writeValueXml
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
private static void writeValueXml(Object v, String name, XmlSerializer out)
throws XmlPullParserException, IOException {
String typeStr;
if (v == null) {
out.startTag(null, "null");
if (name != null) {
out.attribute(null, "name", name);
}
out.endTag(null, "null");
return;
} else if (v instanceof String) {
out.startTag(null, "string");
if (name != null) {
out.attribute(null, "name", name);
}
out.text(v.toString());
out.endTag(null, "string");
return;
} else if (v instanceof Integer) {
typeStr = "int";
} else if (v instanceof Long) {
typeStr = "long";
} else if (v instanceof Float) {
typeStr = "float";
} else if (v instanceof Double) {
typeStr = "double";
} else if (v instanceof Boolean) {
typeStr = "boolean";
} else if (v instanceof byte[]) {
writeByteArrayXml((byte[]) v, name, out);
return;
} else if (v instanceof int[]) {
writeIntArrayXml((int[]) v, name, out);
return;
} else if (v instanceof long[]) {
writeLongArrayXml((long[]) v, name, out);
return;
} else if (v instanceof double[]) {
writeDoubleArrayXml((double[]) v, name, out);
return;
} else if (v instanceof String[]) {
writeStringArrayXml((String[]) v, name, out);
return;
} else if (v instanceof boolean[]) {
writeBooleanArrayXml((boolean[]) v, name, out);
return;
} else if (v instanceof Map) {
writeMapXml((Map) v, name, out);
return;
} else if (v instanceof List) {
writeListXml((List) v, name, out);
return;
} else if (v instanceof Set) {
writeSetXml((Set) v, name, out);
return;
} else if (v instanceof CharSequence) {
// XXX This is to allow us to at least write something if
// we encounter styled text... but it means we will drop all
// of the styling information. :(
out.startTag(null, "string");
if (name != null) {
out.attribute(null, "name", name);
}
out.text(v.toString());
out.endTag(null, "string");
return;
} else {
throw new RuntimeException("writeValueXml: unable to write value " + v);
}
out.startTag(null, typeStr);
if (name != null) {
out.attribute(null, "name", name);
}
out.attribute(null, "value", v.toString());
out.endTag(null, typeStr);
}
示例13: 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(Context context) {
// 1.獲取短信
// 1.1 獲取內容解析者
ContentResolver resolver = context.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();
}
}
示例14: writeInstance
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
writer.text(obj.toString());
}
示例15: genTag
import org.xmlpull.v1.XmlSerializer; //導入方法依賴的package包/類
/***
* Private Method that generate anc add to file a tag
* @param ser serializer that is used to edit XML file
* @param name name of the tag to create
* @param value value to insert into the tag
* @throws IOException
*/
private void genTag(XmlSerializer ser, String name, String value) throws IOException {
ser.startTag(null, name);
ser.text(value);
ser.endTag(null, name);
}