org.xmlpull.v1.XmlSerializer#text ( )源码实例Demo

下面列出了org.xmlpull.v1.XmlSerializer#text ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ratel   文件: ResPluralsValue.java
@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;
        }

        serializer.startTag(null, "item");
        serializer.attribute(null, "quantity", QUANTITY_MAP[i]);
        serializer.text(ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(item.encodeAsResXmlNonEscapedItemValue()));
        serializer.endTag(null, "item");
    }
    serializer.endTag(null, "plurals");
}
 
源代码2 项目: a   文件: XmlUtils.java
/**
 * 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 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 b : val) {
        int h = b >> 4;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
        h = b & 0xff;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
源代码3 项目: mytracks   文件: XmlMapsGDataSerializer.java
private static void serializeUpdateDate(XmlSerializer serializer,
    String updateDate) throws IOException {
  if (StringUtils.isEmpty(updateDate)) {
    return;
  }
  serializer.startTag(null /* ns */, "updated");
  serializer.text(updateDate);
  serializer.endTag(null /* ns */, "updated");
}
 
源代码4 项目: J2ME-Loader   文件: XmlUtils.java
/**
 * 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");
}
 
private static void writePropertyTag(
        XmlSerializer xmlSerializer, String propertyName, String propertyValue)
        throws IOException {
    xmlSerializer.startTag(NAMESPACE, propertyName);
    xmlSerializer.text(propertyValue);
    xmlSerializer.endTag(NAMESPACE, propertyName);
}
 
private static void writePropertyTag(
        XmlSerializer xmlSerializer, String propertyName, byte[] propertyValue)
        throws IOException {
    xmlSerializer.startTag(NAMESPACE, propertyName);
    xmlSerializer.text(Base64.encodeToString(propertyValue, /*flags=*/ Base64.DEFAULT));
    xmlSerializer.endTag(NAMESPACE, propertyName);
}
 
源代码7 项目: JobSchedulerCompat   文件: XmlUtils.java
/**
 * 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;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
        h = b&0xff;
        sb.append(h >= 10 ? ('a'+h-10) : ('0'+h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
public synchronized void writeTo(XmlSerializer out) throws IOException {
    final int N = mPaths.size();
    for (int i = 0; i < N; i++) {
        final String[] segments = mPaths.valueAt(i);
        if (segments != null) {
            out.startTag(NAMESPACE, TAG_PATH);
            out.text(encodeSegments(segments));
            out.endTag(NAMESPACE, TAG_PATH);
        }
    }
}
 
源代码9 项目: mytracks   文件: XmlMapsGDataSerializer.java
private static void serializeSummary(XmlSerializer serializer, String summary)
    throws IOException {
  if (StringUtils.isEmpty(summary)) {
    return;
  }
  serializer.startTag(null /* ns */, "summary");
  serializer.text(summary);
  serializer.endTag(null /* ns */, "summary");
}
 
源代码10 项目: MyBookshelf   文件: XmlUtils.java
/**
 * 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 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 b : val) {
        int h = b >> 4;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
        h = b & 0xff;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
源代码11 项目: HeadsUp   文件: XmlUtils.java
/**
 * 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 void writeByteArrayXml(byte[] val, String name, XmlSerializer out)
        throws 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 (byte b : val) {
        int h = b >> 4;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
        h = b & 0xff;
        sb.append(h >= 10 ? ('a' + h - 10) : ('0' + h));
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}
 
源代码12 项目: AcDisplay   文件: XmlUtils.java
/**
 * Flatten an object's value into an XmlSerializer.  The value can later
 * be read back with readThisValueXml().
 * <p/>
 * 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.
 * @param callback Handler for Object types not recognized.
 * @see #writeMapXml
 * @see #writeListXml
 * @see #readValueXml
 */
private static void writeValueXml(Object v, String name, XmlSerializer out,
                                  WriteMapCallback callback)
        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 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 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 if (callback != null) {
        callback.writeUnknownObject(v, name, out);
        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 项目: WeexOne   文件: XmlUtils.java
/**
 * 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.
 * @param callback Handler for Object types not recognized.
 *
 * @see #writeMapXml
 * @see #writeListXml
 * @see #readValueXml
 */
private static final void writeValueXml(Object v, String name, XmlSerializer out,
                                        WriteMapCallback callback)  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 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 if (callback != null) {
        callback.writeUnknownObject(v, name, out);
        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);
}
 
源代码14 项目: HtmlCompat   文件: XmlUtils.java
/**
 * 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);
}
 
源代码15 项目: Androzic   文件: GpxFiles.java
/**
 * Saves track to file.
 * 
 * @param file valid <code>File</code>
 * @param track <code>Track</code> object containing the list of track points to save
 * @throws IOException
 */
public static void saveTrackToFile(final File file, final Track track) throws IOException
{
	XmlSerializer serializer = Xml.newSerializer();
	serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
	BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false)));
	serializer.setOutput(writer);
	serializer.startDocument("UTF-8", null);
	serializer.setPrefix("", GPX_NAMESPACE);
	serializer.startTag(GPX_NAMESPACE, GpxParser.GPX);
	serializer.attribute("", "creator", "Androzic http://androzic.com");
	serializer.startTag(GPX_NAMESPACE, GpxParser.TRK);
	serializer.startTag(GPX_NAMESPACE, GpxParser.NAME);
	serializer.text(track.name);
	serializer.endTag(GPX_NAMESPACE, GpxParser.NAME);
	serializer.startTag(GPX_NAMESPACE, GpxParser.SRC);
	serializer.text(Androzic.getDeviceName());
	serializer.endTag(GPX_NAMESPACE, GpxParser.SRC);
	
	boolean first = true;
	serializer.startTag(GPX_NAMESPACE, GpxParser.TRKSEG);
	List<TrackPoint> trackPoints = track.getAllPoints();
	for (TrackPoint tp : trackPoints)
	{
		if (!tp.continous && !first)
		{
			serializer.endTag(GPX_NAMESPACE, GpxParser.TRKSEG);
			serializer.startTag(GPX_NAMESPACE, GpxParser.TRKSEG);
		}
		serializer.startTag(GPX_NAMESPACE, GpxParser.TRKPT);
		serializer.attribute("", GpxParser.LAT, String.valueOf(tp.latitude));
		serializer.attribute("", GpxParser.LON, String.valueOf(tp.longitude));
		serializer.startTag(GPX_NAMESPACE, GpxParser.ELE);
		serializer.text(String.valueOf(tp.elevation));
		serializer.endTag(GPX_NAMESPACE, GpxParser.ELE);
		serializer.startTag(GPX_NAMESPACE, GpxParser.TIME);
		serializer.text(GpxParser.trktime.format(new Date(tp.time)));
		serializer.endTag(GPX_NAMESPACE, GpxParser.TIME);
		serializer.endTag(GPX_NAMESPACE, GpxParser.TRKPT);
		first = false;
	}
	serializer.endTag(GPX_NAMESPACE, GpxParser.TRKSEG);
	serializer.endTag(GPX_NAMESPACE, GpxParser.TRK);
	serializer.endTag(GPX_NAMESPACE, GpxParser.GPX);
	serializer.endDocument();
	serializer.flush();
	writer.close();
}
 
源代码16 项目: MyBookshelf   文件: XmlUtils.java
/**
 * Flatten an object's value into an XmlSerializer.  The value can later
 * be read back with readThisValueXml().
 * <p>
 * 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.
 * @param callback Handler for Object types not recognized.
 * @see #writeMapXml
 * @see #writeListXml
 * @see #readValueXml
 */
private static void writeValueXml(Object v, String name, XmlSerializer out,
                                  WriteMapCallback callback) 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 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 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 if (callback != null) {
        callback.writeUnknownObject(v, name, out);
        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);
}
 
源代码17 项目: TelePlus-Android   文件: DashManifestParser.java
/**
 * Parses an event object.
 *
 * @param xpp The current xml parser.
 * @param scratchOutputStream A {@link ByteArrayOutputStream} that's used when parsing the object.
 * @return The serialized byte array.
 * @throws XmlPullParserException If there is any error parsing this node.
 * @throws IOException If there is any error reading from the underlying input stream.
 */
protected byte[] parseEventObject(XmlPullParser xpp, ByteArrayOutputStream scratchOutputStream)
    throws XmlPullParserException, IOException {
  scratchOutputStream.reset();
  XmlSerializer xmlSerializer = Xml.newSerializer();
  xmlSerializer.setOutput(scratchOutputStream, null);
  // Start reading everything between <Event> and </Event>, and serialize them into an Xml
  // byte array.
  xpp.nextToken();
  while (!XmlPullParserUtil.isEndTag(xpp, "Event")) {
    switch (xpp.getEventType()) {
      case (XmlPullParser.START_DOCUMENT):
        xmlSerializer.startDocument(null, false);
        break;
      case (XmlPullParser.END_DOCUMENT):
        xmlSerializer.endDocument();
        break;
      case (XmlPullParser.START_TAG):
        xmlSerializer.startTag(xpp.getNamespace(), xpp.getName());
        for (int i = 0; i < xpp.getAttributeCount(); i++) {
          xmlSerializer.attribute(xpp.getAttributeNamespace(i), xpp.getAttributeName(i),
              xpp.getAttributeValue(i));
        }
        break;
      case (XmlPullParser.END_TAG):
        xmlSerializer.endTag(xpp.getNamespace(), xpp.getName());
        break;
      case (XmlPullParser.TEXT):
        xmlSerializer.text(xpp.getText());
        break;
      case (XmlPullParser.CDSECT):
        xmlSerializer.cdsect(xpp.getText());
        break;
      case (XmlPullParser.ENTITY_REF):
        xmlSerializer.entityRef(xpp.getText());
        break;
      case (XmlPullParser.IGNORABLE_WHITESPACE):
        xmlSerializer.ignorableWhitespace(xpp.getText());
        break;
      case (XmlPullParser.PROCESSING_INSTRUCTION):
        xmlSerializer.processingInstruction(xpp.getText());
        break;
      case (XmlPullParser.COMMENT):
        xmlSerializer.comment(xpp.getText());
        break;
      case (XmlPullParser.DOCDECL):
        xmlSerializer.docdecl(xpp.getText());
        break;
      default: // fall out
    }
    xpp.nextToken();
  }
  xmlSerializer.flush();
  return scratchOutputStream.toByteArray();
}
 
源代码18 项目: LecteurOPUS   文件: Opus.java
public String serialize(){
    XmlSerializer xmlSerializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();

    try {
        xmlSerializer.setOutput(writer);

        //Start Document
        xmlSerializer.startDocument("UTF-8", true);
        //Open Tag <file>
        xmlSerializer.startTag("", "Opus");

        xmlSerializer.startTag("", "ID");
        xmlSerializer.text(bytesToHex(m_dataID));
        xmlSerializer.endTag("", "ID");

        xmlSerializer.startTag("", "Expiration");
        xmlSerializer.text(bytesToHex(m_dataExp));
        xmlSerializer.endTag("", "Expiration");

        xmlSerializer.startTag("", "Transit");
        for (int i = 0; i < 3; i++) {
            xmlSerializer.startTag("", "List");
            xmlSerializer.attribute("", "index", Integer.toString(i));
            xmlSerializer.text(bytesToHex(m_dataTransit[i]));
            xmlSerializer.endTag("", "List");
        }
        xmlSerializer.endTag("", "Transit");

        xmlSerializer.startTag("", "Subscription");
        for (int i = 0; i < 4; i++) {
            xmlSerializer.startTag("", "List");
            xmlSerializer.attribute("", "index", Integer.toString(i));
            xmlSerializer.text(bytesToHex(m_dataSubscription[i]));
            xmlSerializer.endTag("", "List");
        }
        xmlSerializer.endTag("", "Subscription");

        xmlSerializer.startTag("", "Ticket");
        for (int i = 0; i < 4; i++) {
            xmlSerializer.startTag("", "List");
            xmlSerializer.attribute("", "index", Integer.toString(i));
            xmlSerializer.text(bytesToHex(m_dataTicket[i]));
            xmlSerializer.endTag("", "List");
        }
        xmlSerializer.endTag("", "Ticket");

        xmlSerializer.endTag("", "Opus");

        xmlSerializer.endDocument();

        return writer.toString();
    }
    catch (IOException e){
        Log.e("Opus", "Error serialize");
        return "";
    }
}
 
源代码19 项目: tysq-android   文件: XmlUtils.java
/**
 * 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
 */
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);
}
 
源代码20 项目: XPrivacy   文件: XmlUtils.java
/**
 * 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);
}