private String serialize(Element e, int intent){ try{ XmlSerializer s = Xml.newSerializer(); StringWriter sw = new StringWriter(); s.setOutput(sw); s.startDocument("utf-8", null); String spaces = null; if(intent > 0){ char[] chars = new char[intent]; Arrays.fill(chars, ' '); spaces = new String(chars); } serialize(root, s, 0, spaces); s.endDocument(); return sw.toString(); }catch(Exception ex){ ex.printStackTrace(); } return null; }
public static String serialize(Set<String> set) { if (set == null) { set = Collections.emptySet(); } StringWriter writer = new StringWriter(); XmlSerializer serializer = Xml.newSerializer(); try { serializer.setOutput(writer); serializer.startTag(NAMESPACE, SET_TAG); for (String string : set) { serializer.startTag(NAMESPACE, STRING_TAG) // .text(string) // .endTag(NAMESPACE, STRING_TAG); } serializer.endTag(NAMESPACE, SET_TAG) // .endDocument(); } catch (IllegalArgumentException | IOException | IllegalStateException e) { // should never happen } return writer.toString(); }
/** * 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(); }
/** * 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(); }
private void writeUserListLocked() { FileOutputStream fos = null; AtomicFile userListFile = new AtomicFile(mUserListFile); try { fos = userListFile.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_USERS); serializer.attribute(null, ATTR_NEXT_SERIAL_NO, Integer.toString(mNextSerialNumber)); serializer.attribute(null, ATTR_USER_VERSION, Integer.toString(mUserVersion)); for (int i = 0; i < mUsers.size(); i++) { VUserInfo user = mUsers.valueAt(i); serializer.startTag(null, TAG_USER); serializer.attribute(null, ATTR_ID, Integer.toString(user.id)); serializer.endTag(null, TAG_USER); } serializer.endTag(null, TAG_USERS); serializer.endDocument(); userListFile.finishWrite(fos); } catch (Exception e) { userListFile.failWrite(fos); VLog.e(LOG_TAG, "Error writing user list"); } }
serializer.endDocument(); userFile.finishWrite(fos); } catch (Exception ioe) {
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); } }
serializer.endTag("", "trk"); serializer.endTag("", "gpx"); serializer.endDocument(); serializer.flush(); } catch (IOException e) {
serializer.endDocument(); serializer.flush();
break; case (XmlPullParser.END_DOCUMENT): xmlSerializer.endDocument(); break; case (XmlPullParser.START_TAG):
public void endDocument() throws IOException, IllegalArgumentException, IllegalStateException { xs.endDocument(); }
public void endDocument() throws IOException, IllegalArgumentException, IllegalStateException { xs.endDocument(); }
private String end() throws IOException { xmlSerializer.endTag(ns, "osm"); xmlSerializer.endDocument(); return stringWriter.toString(); }
/** * Ends a XML document. */ public static void endXmlDocument(XmlSerializer writer) throws IOException { assert writer != null; // end document writer.endDocument(); writer.flush(); writer.toString(); }
@SuppressLint("SetWorldReadable") private void endXml() { try { mXmlSerializer.endTag(null, "screenshots"); mXmlSerializer.endDocument(); mXmlSerializer.flush(); } catch (IOException e) { throw new RuntimeException(e); } try { mOutputStream.close(); } catch (IOException e) { throw new RuntimeException(e); } }
private void serialize( XmlSerializer serializer, String elementName, Object element, boolean errorOnUnknown) throws IOException { String elementAlias = ""; if (elementName != null) { int colon = elementName.indexOf(':'); if (colon != -1) { elementAlias = elementName.substring(0, colon); } } startDoc(serializer, element, errorOnUnknown, elementAlias).serialize(serializer, elementName); serializer.endDocument(); }
void endTestSuites() { try { if (mTestSuiteSerializer != null) { mTestSuiteSerializer.endTag(null, "testsuites"); mTestSuiteSerializer.endDocument(); mTestSuiteSerializer.flush(); } if (mWriter != null) { mWriter.flush(); mWriter.close(); } } catch (IOException e) { throw new RuntimeException(e); } } }
private void serialize(XmlSerializer serializer, String elementNamespaceUri, String elementLocalName, Object element, boolean errorOnUnknown) throws IOException { String elementAlias = elementNamespaceUri == null ? null : getAliasForUri(elementNamespaceUri); startDoc(serializer, element, errorOnUnknown, elementAlias).serialize( serializer, elementNamespaceUri, elementLocalName); serializer.endDocument(); }
/** * 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(); }
private void serializeDocument(XmlDocument doc, XmlSerializer ser) { try { ser.startDocument(doc.getCharacterEncodingScheme(), doc.isStandalone()); } catch (IOException e) { throw new XmlBuilderException("serializing XML document start failed", e); } if(doc.getDocumentElement() != null) { serializeFragment(doc.getDocumentElement(), ser); } else { throw new XmlBuilderException("could not serialize document without root element "+doc+": "); } try { ser.endDocument(); } catch (IOException e) { throw new XmlBuilderException("serializing XML document end failed", e); } }