Java Code Examples for org.xmlpull.v1.XmlSerializer#setFeature()

The following examples show how to use org.xmlpull.v1.XmlSerializer#setFeature() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessibilityNodeInfoDumper.java    From za-Farmer with MIT License 6 votes vote down vote up
public static void dumpWindowHierarchy(UiDevice device, OutputStream out) throws IOException {
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    serializer.setOutput(out, "UTF-8");

    serializer.startDocument("UTF-8", true);
    serializer.startTag("", "hierarchy"); // TODO(allenhair): Should we use a namespace?
    serializer.attribute("", "rotation", Integer.toString(device.getDisplayRotation()));

    for (AccessibilityNodeInfo root : device.getWindowRoots()) {
        dumpNodeRec(root, serializer, 0, device.getDisplayWidth(), device.getDisplayHeight());
    }

    serializer.endTag("", "hierarchy");
    serializer.endDocument();
}
 
Example 2
Source File: TaskPersister.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private StringWriter saveToXml(TaskRecord task) throws IOException, XmlPullParserException {
    if (DEBUG) Slog.d(TAG, "saveToXml: task=" + task);
    final XmlSerializer xmlSerializer = new FastXmlSerializer();
    StringWriter stringWriter = new StringWriter();
    xmlSerializer.setOutput(stringWriter);

    if (DEBUG) xmlSerializer.setFeature(
            "http://xmlpull.org/v1/doc/features.html#indent-output", true);

    // save task
    xmlSerializer.startDocument(null, true);

    xmlSerializer.startTag(null, TAG_TASK);
    task.saveToXml(xmlSerializer);
    xmlSerializer.endTag(null, TAG_TASK);

    xmlSerializer.endDocument();
    xmlSerializer.flush();

    return stringWriter;
}
 
Example 3
Source File: FormulaList.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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_MMT_SCHEMA);
        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;
}
 
Example 4
Source File: ActivityDns.java    From NetGuard with GNU General Public License v3.0 5 votes vote down vote up
private void xmlExport(OutputStream out) throws IOException {
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, "UTF-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    serializer.startTag(null, "netguard");

    DateFormat df = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.US); // RFC 822

    try (Cursor cursor = DatabaseHelper.getInstance(this).getDns()) {
        int colTime = cursor.getColumnIndex("time");
        int colQName = cursor.getColumnIndex("qname");
        int colAName = cursor.getColumnIndex("aname");
        int colResource = cursor.getColumnIndex("resource");
        int colTTL = cursor.getColumnIndex("ttl");
        while (cursor.moveToNext()) {
            long time = cursor.getLong(colTime);
            String qname = cursor.getString(colQName);
            String aname = cursor.getString(colAName);
            String resource = cursor.getString(colResource);
            int ttl = cursor.getInt(colTTL);

            serializer.startTag(null, "dns");
            serializer.attribute(null, "time", df.format(time));
            serializer.attribute(null, "qname", qname);
            serializer.attribute(null, "aname", aname);
            serializer.attribute(null, "resource", resource);
            serializer.attribute(null, "ttl", Integer.toString(ttl));
            serializer.endTag(null, "dns");
        }
    }

    serializer.endTag(null, "netguard");
    serializer.endDocument();
    serializer.flush();
}
 
Example 5
Source File: OrchestrationXmlTestRunListener.java    From android-test with Apache License 2.0 5 votes vote down vote up
/** Creates a report file and populates it with the report data from the completed tests. */
private void generateDocument(File reportDir, long elapsedTime) {
  String timestamp = getTimestamp();

  OutputStream stream = null;
  try {
    stream = createOutputResultStream(reportDir);
    XmlSerializer serializer = XmlPullParserFactory.newInstance().newSerializer();
    serializer.setOutput(stream, UTF_8);
    serializer.startDocument(UTF_8, null);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    // TODO: insert build info
    printTestResults(serializer, timestamp, elapsedTime);
    serializer.endDocument();
    String msg =
        String.format(
            "XML test result file generated at %s. %s",
            getAbsoluteReportPath(), runResult.getTextSummary());
    Log.i(LOG_TAG, msg);
  } catch (IOException | XmlPullParserException e) {
    Log.e(LOG_TAG, "Failed to generate report data", e);
    // TODO: consider throwing exception
  } finally {
    if (stream != null) {
      try {
        stream.close();
      } catch (IOException ignored) {
      }
    }
  }
}
 
Example 6
Source File: KmlFiles.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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
{
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
	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("", KML_NAMESPACE);
	serializer.startTag(KML_NAMESPACE, KmlParser.KML);
	serializer.startTag(KML_NAMESPACE, KmlParser.DOCUMENT);
	serializer.startTag(KML_NAMESPACE, KmlParser.STYLE);
	serializer.attribute("", KmlParser.ID, "trackStyle");
	serializer.startTag(KML_NAMESPACE, KmlParser.LINESTYLE);
	serializer.startTag(KML_NAMESPACE, KmlParser.COLOR);
	serializer.text(String.format("%08X", KmlParser.reverseColor(track.color)));
	serializer.endTag(KML_NAMESPACE, KmlParser.COLOR);
	serializer.startTag(KML_NAMESPACE, KmlParser.WIDTH);
	serializer.text(String.valueOf(track.width));
	serializer.endTag(KML_NAMESPACE, KmlParser.WIDTH);
	serializer.endTag(KML_NAMESPACE, KmlParser.LINESTYLE);
	serializer.endTag(KML_NAMESPACE, KmlParser.STYLE);
	serializer.startTag(KML_NAMESPACE, KmlParser.FOLDER);
	serializer.startTag(KML_NAMESPACE, KmlParser.NAME);
	serializer.text(track.name);
	serializer.endTag(KML_NAMESPACE, KmlParser.NAME);
	serializer.startTag(KML_NAMESPACE, KmlParser.OPEN);
	serializer.text("0");
	serializer.endTag(KML_NAMESPACE, KmlParser.OPEN);
	serializer.startTag(KML_NAMESPACE, KmlParser.TIMESPAN);
	serializer.startTag(KML_NAMESPACE, KmlParser.BEGIN);
	serializer.text(sdf.format(new Date(track.getPoint(0).time)));
	serializer.endTag(KML_NAMESPACE, KmlParser.BEGIN);
	serializer.startTag(KML_NAMESPACE, KmlParser.END);
	serializer.text(sdf.format(new Date(track.getLastPoint().time)));
	serializer.endTag(KML_NAMESPACE, KmlParser.END);
	serializer.endTag(KML_NAMESPACE, KmlParser.TIMESPAN);
	serializer.startTag(KML_NAMESPACE, KmlParser.STYLE);
	serializer.startTag(KML_NAMESPACE, KmlParser.LISTSTYLE);
	serializer.startTag(KML_NAMESPACE, KmlParser.LISTITEMTYPE);
	serializer.text("checkHideChildren");
	serializer.endTag(KML_NAMESPACE, KmlParser.LISTITEMTYPE);
	serializer.endTag(KML_NAMESPACE, KmlParser.LISTSTYLE);
	serializer.endTag(KML_NAMESPACE, KmlParser.STYLE);
	
	int part = 1;
	boolean first = true;
	startTrackPart(serializer, part, track.name);
	List<TrackPoint> trackPoints = track.getAllPoints();
	synchronized (trackPoints)
	{
		for (TrackPoint tp : trackPoints)
		{
			if (!tp.continous && !first)
			{
				stopTrackPart(serializer);
				part++;
				startTrackPart(serializer, part, track.name);
			}
			serializer.text(String.format("%f,%f,%f ", tp.longitude, tp.latitude, tp.elevation));
			first = false;
		}
	}
	stopTrackPart(serializer);
	serializer.endTag(KML_NAMESPACE, KmlParser.FOLDER);
	serializer.endTag(KML_NAMESPACE, KmlParser.DOCUMENT);
	serializer.endTag(KML_NAMESPACE, KmlParser.KML);
	serializer.endDocument();
	serializer.flush();
	writer.close();
}
 
Example 7
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
void writeUserLP(UserData userData, OutputStream os)
        throws IOException, XmlPullParserException {
    // XmlSerializer serializer = XmlUtils.serializerInstance();
    final XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(os, StandardCharsets.UTF_8.name());
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

    final UserInfo userInfo = userData.info;
    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.lastLoggedInFingerprint != null) {
        serializer.attribute(null, ATTR_LAST_LOGGED_IN_FINGERPRINT,
                userInfo.lastLoggedInFingerprint);
    }
    if (userInfo.iconPath != null) {
        serializer.attribute(null,  ATTR_ICON_PATH, userInfo.iconPath);
    }
    if (userInfo.partial) {
        serializer.attribute(null, ATTR_PARTIAL, "true");
    }
    if (userInfo.guestToRemove) {
        serializer.attribute(null, ATTR_GUEST_TO_REMOVE, "true");
    }
    if (userInfo.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID) {
        serializer.attribute(null, ATTR_PROFILE_GROUP_ID,
                Integer.toString(userInfo.profileGroupId));
    }
    serializer.attribute(null, ATTR_PROFILE_BADGE,
            Integer.toString(userInfo.profileBadge));
    if (userInfo.restrictedProfileParentId != UserInfo.NO_PROFILE_GROUP_ID) {
        serializer.attribute(null, ATTR_RESTRICTED_PROFILE_PARENT_ID,
                Integer.toString(userInfo.restrictedProfileParentId));
    }
    // Write seed data
    if (userData.persistSeedData) {
        if (userData.seedAccountName != null) {
            serializer.attribute(null, ATTR_SEED_ACCOUNT_NAME, userData.seedAccountName);
        }
        if (userData.seedAccountType != null) {
            serializer.attribute(null, ATTR_SEED_ACCOUNT_TYPE, userData.seedAccountType);
        }
    }
    if (userInfo.name != null) {
        serializer.startTag(null, TAG_NAME);
        serializer.text(userInfo.name);
        serializer.endTag(null, TAG_NAME);
    }
    synchronized (mRestrictionsLock) {
        UserRestrictionsUtils.writeRestrictions(serializer,
                mBaseUserRestrictions.get(userInfo.id), TAG_RESTRICTIONS);
        UserRestrictionsUtils.writeRestrictions(serializer,
                mDevicePolicyLocalUserRestrictions.get(userInfo.id),
                TAG_DEVICE_POLICY_RESTRICTIONS);
        UserRestrictionsUtils.writeRestrictions(serializer,
                mDevicePolicyGlobalUserRestrictions.get(userInfo.id),
                TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS);
    }

    if (userData.account != null) {
        serializer.startTag(null, TAG_ACCOUNT);
        serializer.text(userData.account);
        serializer.endTag(null, TAG_ACCOUNT);
    }

    if (userData.persistSeedData && userData.seedAccountOptions != null) {
        serializer.startTag(null, TAG_SEED_ACCOUNT_OPTIONS);
        userData.seedAccountOptions.saveToXml(serializer);
        serializer.endTag(null, TAG_SEED_ACCOUNT_OPTIONS);
    }

    serializer.endTag(null, TAG_USER);

    serializer.endDocument();
}
 
Example 8
Source File: XmlUtils.java    From Android-PreferencesManager with Apache License 2.0 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML. The map can later be read
 * back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static final void writeMapXml(Map val, OutputStream out) throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 9
Source File: XmlUtils.java    From HeadsUp with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML.  The map can later be
 * read back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static void writeMapXml(Map val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 10
Source File: XmlUtils.java    From JobSchedulerCompat with Apache License 2.0 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML.  The map can later be
 * read back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static final void writeMapXml(Map val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 11
Source File: XmlUtils.java    From WeexOne with MIT License 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML.  The map can later be
 * read back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static final void writeMapXml(Map val, OutputStream out)
    throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 12
Source File: XmlUtils.java    From WeexOne with MIT License 3 votes vote down vote up
/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static final void writeListXml(List val, OutputStream out)
    throws XmlPullParserException, java.io.IOException
{
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeListXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 13
Source File: XmlUtils.java    From PreferenceFragment with Apache License 2.0 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML.  The map can later be
 * read back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static final void writeMapXml(Map val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 14
Source File: XmlUtils.java    From XPrivacy with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML.  The map can later be
 * read back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static final void writeMapXml(Map val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 15
Source File: XmlUtils.java    From AcDisplay with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static void writeListXml(List val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeListXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 16
Source File: XmlUtils.java    From MyBookshelf with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static void writeListXml(List val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeListXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 17
Source File: XmlUtils.java    From JobSchedulerCompat with Apache License 2.0 3 votes vote down vote up
/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static final void writeListXml(List val, OutputStream out)
throws XmlPullParserException, java.io.IOException
{
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeListXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 18
Source File: XmlUtils.java    From MyBookshelf with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML.  The map can later be
 * read back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static void writeMapXml(Map val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 19
Source File: XmlUtils.java    From HtmlCompat with Apache License 2.0 3 votes vote down vote up
/**
 * Flatten a List into an output stream as XML.  The list can later be
 * read back with readListXml().
 *
 * @param val The list to be flattened.
 * @param out Where to write the XML data.
 *
 * @see #writeListXml(List, String, XmlSerializer)
 * @see #writeMapXml
 * @see #writeValueXml
 * @see #readListXml
 */
public static final void writeListXml(List val, OutputStream out)
        throws XmlPullParserException, java.io.IOException
{
    XmlSerializer serializer = Xml.newSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeListXml(val, null, serializer);
    serializer.endDocument();
}
 
Example 20
Source File: XmlUtils.java    From a with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Flatten a Map into an output stream as XML.  The map can later be
 * read back with readMapXml().
 *
 * @param val The map to be flattened.
 * @param out Where to write the XML data.
 * @see #writeMapXml(Map, String, XmlSerializer)
 * @see #writeListXml
 * @see #writeValueXml
 * @see #readMapXml
 */
public static void writeMapXml(Map val, OutputStream out)
        throws XmlPullParserException, java.io.IOException {
    XmlSerializer serializer = new FastXmlSerializer();
    serializer.setOutput(out, "utf-8");
    serializer.startDocument(null, true);
    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
    writeMapXml(val, null, serializer);
    serializer.endDocument();
}