예제 #1
0
  /**
   * Flatten a List into an XmlSerializer. The list can later be read back with readThisListXml().
   *
   * @param val The list to be flattened.
   * @param name Name attribute to include with this list's tag, or null for none.
   * @param out XmlSerializer to write the list into.
   * @see #writeListXml(List, OutputStream)
   * @see #writeMapXml
   * @see #writeValueXml
   * @see #readListXml
   */
  public static final void writeListXml(List 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, "list");
    if (name != null) {
      out.attribute(null, "name", name);
    }

    int N = val.size();
    int i = 0;
    while (i < N) {
      writeValueXml(val.get(i), null, out);
      i++;
    }

    out.endTag(null, "list");
  }
예제 #2
0
  /**
   * 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");
  }