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; }
/** * 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.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
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.startDocument("UTF-8", true); serializer.startTag("", "gpx"); serializer.attribute("", "version", "1.1");
serializer.setOutput(os, "UTF-8"); serializer.startDocument(null, Boolean.TRUE);
switch (xpp.getEventType()) { case (XmlPullParser.START_DOCUMENT): xmlSerializer.startDocument(null, false); break; case (XmlPullParser.END_DOCUMENT):
public void startDocument(String encoding, Boolean standalone) throws IOException, IllegalArgumentException, IllegalStateException { xs.startDocument(encoding, standalone); }
public void startDocument(String encoding, Boolean standalone) throws IOException, IllegalArgumentException, IllegalStateException { xs.startDocument(encoding, standalone); }
void startJUnitOutput(Writer writer) { try { mWriter = writer; mTestSuiteSerializer = newSerializer(mWriter); mTestSuiteSerializer.startDocument(null, null); mTestSuiteSerializer.startTag(null, "testsuites"); mTestSuiteSerializer.startTag(null, "testsuite"); } catch (Exception e) { throw new RuntimeException(e); } }
private void initXml() { if (mOutputStream != null) { return; } try { mOutputStream = new FileOutputStream(getMetadataFile()); mXmlSerializer = Xml.newSerializer(); mXmlSerializer.setOutput(mOutputStream, "utf-8"); mXmlSerializer.startDocument("utf-8", null); mXmlSerializer.startTag(null, "screenshots"); } catch (IOException e) { throw new RuntimeException(e); } }
void startJUnitOutput(Writer writer) { try { mWriter = writer; mTestSuiteSerializer = newSerializer(mWriter); mTestSuiteSerializer.startDocument(null, null); mTestSuiteSerializer.startTag(null, "testsuites"); mTestSuiteSerializer.startTag(null, "testsuite"); } catch (Exception e) { throw new RuntimeException(e); } }
private ElementSerializer startDoc( XmlSerializer serializer, Object element, boolean errorOnUnknown, String elementAlias) throws IOException { serializer.startDocument(null, null); SortedSet<String> aliases = new TreeSet<String>(); computeAliases(element, aliases); if (elementAlias != null) { aliases.add(elementAlias); } for (String alias : aliases) { String uri = getNamespaceUriForAliasHandlingUnknown(errorOnUnknown, alias); serializer.setPrefix(alias, uri); } return new ElementSerializer(element, errorOnUnknown); }
/** * Starts a XML document. */ public static void startXmlDocument(XmlSerializer writer) throws IOException { assert writer != null; writer.setPrefix(XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM); writer.setPrefix(XMLConstants.PREFIX_CMIS, XMLConstants.NAMESPACE_CMIS); writer.setPrefix(XMLConstants.PREFIX_RESTATOM, XMLConstants.NAMESPACE_RESTATOM); writer.setPrefix(XMLConstants.PREFIX_APACHE_CHEMISTY, XMLConstants.NAMESPACE_APACHE_CHEMISTRY); writer.startDocument("UTF-8", false); }
private void start() throws IOException { xmlSerializer.setOutput(stringWriter); xmlSerializer.startDocument("UTF-8", null); xmlSerializer.startTag(ns, "osm"); xmlSerializer.attribute(ns, "version", OSM_API_VERSION); xmlSerializer.attribute(ns, "generator", generator); xmlSerializer.attribute(ns, "user", osmUser); }
/** * 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); } }
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); } }