本文整理汇总了Java中org.xmlpull.v1.XmlSerializer.startTag方法的典型用法代码示例。如果您正苦于以下问题:Java XmlSerializer.startTag方法的具体用法?Java XmlSerializer.startTag怎么用?Java XmlSerializer.startTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmlpull.v1.XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.startTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeSetXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
public static final void writeSetXml(Set 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, "set");
if (name != null) {
out.attribute(null, "name", name);
}
for (Object v : val) {
writeValueXml(v, null, out);
}
out.endTag(null, "set");
}
示例2: filterExport
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
private void filterExport(XmlSerializer serializer) throws IOException {
Cursor cursor = DatabaseHelper.getInstance(this).getAccess();
int colUid = cursor.getColumnIndex("uid");
int colVersion = cursor.getColumnIndex("version");
int colProtocol = cursor.getColumnIndex("protocol");
int colDAddr = cursor.getColumnIndex("daddr");
int colDPort = cursor.getColumnIndex("dport");
int colTime = cursor.getColumnIndex("time");
int colBlock = cursor.getColumnIndex("block");
while (cursor.moveToNext())
for (String pkg : getPackages(cursor.getInt(colUid))) {
serializer.startTag(null, "rule");
serializer.attribute(null, "pkg", pkg);
serializer.attribute(null, "version", Integer.toString(cursor.getInt(colVersion)));
serializer.attribute(null, "protocol", Integer.toString(cursor.getInt(colProtocol)));
serializer.attribute(null, "daddr", cursor.getString(colDAddr));
serializer.attribute(null, "dport", Integer.toString(cursor.getInt(colDPort)));
serializer.attribute(null, "time", Long.toString(cursor.getLong(colTime)));
serializer.attribute(null, "block", Integer.toString(cursor.getInt(colBlock)));
serializer.endTag(null, "rule");
}
cursor.close();
}
示例3: writeConstraintsToXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* Write out a tag with data identifying this job's constraints. If the constraint isn't here it doesn't apply.
*/
private void writeConstraintsToXml(XmlSerializer out, JobStatus jobStatus) throws IOException {
out.startTag(null, XML_TAG_PARAMS_CONSTRAINTS);
if (jobStatus.needsAnyConnectivity()) {
out.attribute(null, "connectivity", Boolean.toString(true));
}
if (jobStatus.needsMeteredConnectivity()) {
out.attribute(null, "metered", Boolean.toString(true));
}
if (jobStatus.needsUnmeteredConnectivity()) {
out.attribute(null, "unmetered", Boolean.toString(true));
}
if (jobStatus.needsNonRoamingConnectivity()) {
out.attribute(null, "not-roaming", Boolean.toString(true));
}
if (jobStatus.hasIdleConstraint()) {
out.attribute(null, "idle", Boolean.toString(true));
}
if (jobStatus.hasChargingConstraint()) {
out.attribute(null, "charging", Boolean.toString(true));
}
if (jobStatus.hasBatteryNotLowConstraint()) {
out.attribute(null, "battery-not-low", Boolean.toString(true));
}
out.endTag(null, XML_TAG_PARAMS_CONSTRAINTS);
}
示例4: writeToXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* XML interface: procedure returns string that contains XML representation of this formula
*/
public void writeToXml(XmlSerializer serializer, String key) throws Exception
{
if (onStartWriteXmlTag(serializer, key))
{
return;
}
for (TermField t : terms)
{
serializer.startTag(FormulaList.XML_NS, FormulaList.XML_TERM_TAG);
serializer.attribute(FormulaList.XML_NS, FormulaList.XML_PROP_KEY, t.getTermKey());
if (onStartWriteXmlTag(serializer, t.getTermKey()))
{
continue;
}
if (t.isWritable)
{
t.writeToXml(serializer);
}
serializer.endTag(FormulaList.XML_NS, FormulaList.XML_TERM_TAG);
}
}
示例5: 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);
}
}
示例6: writeMapXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* Flatten a Map into an XmlSerializer. The map can later be read back
* with readThisMapXml().
*
* @param val The map to be flattened.
* @param name Name attribute to include with this list's tag, or null for
* none.
* @param out XmlSerializer to write the map into.
*
* @see #writeMapXml(Map, OutputStream)
* @see #writeListXml
* @see #writeValueXml
* @see #readMapXml
*/
public static final void writeMapXml(Map val, String name, XmlSerializer out)
throws XmlPullParserException, java.io.IOException
{
if (val == null) {
out.startTag(null, "null");
out.endTag(null, "null");
return;
}
Set s = val.entrySet();
Iterator i = s.iterator();
out.startTag(null, "map");
if (name != null) {
out.attribute(null, "name", name);
}
while (i.hasNext()) {
Map.Entry e = (Map.Entry)i.next();
writeValueXml(e.getValue(), (String)e.getKey(), out);
}
out.endTag(null, "map");
}
示例7: writeIntArrayXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* Flatten an int[] into an XmlSerializer. The list can later be read back
* with readThisIntArrayXml().
*
* @param val The int 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
* @see #readThisIntArrayXml
*/
public static final void writeIntArrayXml(int[] 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, "int-array");
if (name != null) {
out.attribute(null, "name", name);
}
final int N = val.length;
out.attribute(null, "num", Integer.toString(N));
for (int i=0; i<N; i++) {
out.startTag(null, "item");
out.attribute(null, "value", Integer.toString(val[i]));
out.endTag(null, "item");
}
out.endTag(null, "int-array");
}
示例8: 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;
}
示例9: serializeBody
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
@Override
protected void serializeBody(XmlSerializer serializer, ResResource res)
throws AndrolibException, IOException {
for (Duo<ResReferenceValue, ResIntValue> duo : mItems) {
int intVal = duo.m2.getValue();
serializer.startTag(null, "enum");
serializer.attribute(null, "name", duo.m1.getReferent().getName());
serializer.attribute(null, "value", String.valueOf(intVal));
serializer.endTag(null, "enum");
}
}
示例10: serializeToResValuesXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
@Override
public void serializeToResValuesXml(XmlSerializer serializer,
ResResource res) throws IOException, AndrolibException {
serializer.startTag(null, "item");
serializer
.attribute(null, "type", res.getResSpec().getType().getName());
serializer.attribute(null, "name", res.getResSpec().getName());
serializer.endTag(null, "item");
}
示例11: writeIntArrayXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* Flatten an int[] into an XmlSerializer. The list can later be read back
* with readThisIntArrayXml().
*
* @param val The int 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
* @see #readThisIntArrayXml
*/
public static final void writeIntArrayXml(int[] 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, "int-array");
if (name != null) {
out.attribute(null, "name", name);
}
final int N = val.length;
out.attribute(null, "num", Integer.toString(N));
for (int i=0; i<N; i++) {
out.startTag(null, "item");
out.attribute(null, "value", Integer.toString(val[i]));
out.endTag(null, "item");
}
out.endTag(null, "int-array");
}
示例12: writeToXmlImpl
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
/**
* Serializes all Blocks in the given list and writes them to the either the output stream or
* writer, whichever is not null.
*
* @param toSerialize A list of Blocks to serialize.
* @param os An OutputStream to write the blocks to.
* @param writer A writer to write the blocks to, if {@code os} is null.
* @param options The options to configure the block serialization. If omitted,
* {@link IOOptions#WRITE_ALL_DATA} will be used by default.
*
* @throws BlocklySerializerException
*/
public static void writeToXmlImpl(final @NonNull List<Block> toSerialize,
@Nullable OutputStream os, @Nullable Writer writer,
@Nullable IOOptions options)
throws BlocklySerializerException {
final IOOptions finalOptions = options == null ? IOOptions.WRITE_ALL_DATA : options;
XmlContentWriter contentWriter = new XmlContentWriter() {
@Override
public void write(XmlSerializer serializer) throws IOException {
serializer.setPrefix("", XML_NAMESPACE);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(XML_NAMESPACE, "xml");
for (int i = 0; i < toSerialize.size(); i++) {
toSerialize.get(i).serialize(serializer, true, finalOptions);
}
serializer.endTag(XML_NAMESPACE, "xml");
}
};
try {
if (os != null) {
writeXml(os, contentWriter);
} else {
writeXml(writer, contentWriter);
}
} catch (IOException e) {
throw new BlocklySerializerException(e);
}
}
示例13: serializeToResValuesXml
import org.xmlpull.v1.XmlSerializer; //导入方法依赖的package包/类
@Override
public void serializeToResValuesXml(XmlSerializer serializer,
ResResource res) throws IOException, AndrolibException {
String type = res.getResSpec().getType().getName();
boolean item = !"reference".equals(mType) && !type.equals(mType);
String body = encodeAsResXmlValue();
// check for resource reference
if (!type.equalsIgnoreCase("color")) {
if (body.contains("@")) {
if (!res.getFilePath().contains("string")) {
item = true;
}
}
}
// check for using attrib as node or item
String tagName = item ? "item" : type;
serializer.startTag(null, tagName);
if (item) {
serializer.attribute(null, "type", type);
}
serializer.attribute(null, "name", res.getResSpec().getName());
serializeExtraXmlAttrs(serializer, res);
if (!body.isEmpty()) {
serializer.ignorableWhitespace(body);
}
serializer.endTag(null, tagName);
}
示例14: 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);
}
示例15: 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();
}
}