当前位置: 首页>>代码示例>>Java>>正文


Java XmlSerializer.text方法代码示例

本文整理汇总了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");
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:21,代码来源:ResPluralsValue.java

示例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);
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:25,代码来源:ResArrayValue.java

示例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);
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:41,代码来源:VUserManagerService.java

示例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);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:9,代码来源:SettingsExporter.java

示例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");
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:44,代码来源:XmlUtils.java

示例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);
   }
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:15,代码来源:XmlPullUtil.java

示例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");
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:16,代码来源:Field.java

示例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");
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:8,代码来源:MutatorTest.java

示例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);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:70,代码来源:SettingsExporter.java

示例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();
    }
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:68,代码来源:PhoneUtils.java

示例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);
}
 
开发者ID:Pixplicity,项目名称:HtmlCompat,代码行数:82,代码来源:XmlUtils.java

示例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);
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:78,代码来源:XmlUtils.java

示例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();
    }
}
 
开发者ID:hushengjun,项目名称:FastAndroid,代码行数:68,代码来源:PhoneManager.java

示例14: writeInstance

import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
public void writeInstance(XmlSerializer writer, Object obj) throws IOException {
   writer.text(obj.toString());
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:4,代码来源:MarshalDouble.java

示例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);
}
 
开发者ID:Visions-Team,项目名称:eBread,代码行数:13,代码来源:SettingManager.java


注:本文中的org.xmlpull.v1.XmlSerializer.text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。