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); } }
private static void writeKeyAndPrettyValueFromSetting(XmlSerializer serializer, String key, String literalValue) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag(null, VALUE_ELEMENT); serializer.attribute(null, KEY_ATTRIBUTE, key); if (literalValue != null) { serializer.text(literalValue); } serializer.endTag(null, VALUE_ELEMENT); }
/** * 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(); }
@Override protected void serializeBody(XmlSerializer serializer, ResResource res) throws AndrolibException, IOException { for (int i = 0; i < mItems.length; i++) { FlagItem item = mItems[i]; serializer.startTag(null, "flag"); serializer.attribute(null, "name", item.getValue()); serializer.attribute(null, "value", String.format("0x%08x", item.flag)); serializer.endTag(null, "flag"); } }
scratchOutputStream.reset(); XmlSerializer xmlSerializer = Xml.newSerializer(); xmlSerializer.setOutput(scratchOutputStream, C.UTF8_NAME); 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)); 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):
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(); }
serializer.startTag(null, tagName); if (item) { serializer.attribute(null, "type", type); serializer.attribute(null, "name", res.getResSpec().getName()); serializer.ignorableWhitespace(body); serializer.endTag(null, tagName);
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 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; }
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); }
public void setOutput(OutputStream os, String encoding) throws IOException, IllegalArgumentException, IllegalStateException { xs.setOutput(os, encoding); }
/** * Saves an Animation to disk as an XML file. * @param file the full path to the destination file * @param a the Animation to save * @throws XmlPullParserException * @throws IOException * @throws IllegalArgumentException * @throws FileNotFoundException */ static void saveAnimation( String file, Animation a, ChannelsParameterSource source, Set<SynchronizedPointGroup> syncPointGroups) throws XmlPullParserException, IOException, IllegalArgumentException, FileNotFoundException{ XmlSerializer xs = XMLUtils.getXmlFileSerializer(file); xs.startDocument(null, null); xs.text("\n"); //new line after xml version tag. writeAnimation(xs, a, file, source, syncPointGroups); xs.endDocument(); xs.flush(); }
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 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); } }
public static void writeStringAttribute(XmlSerializer out, String name, String value) throws IOException { if (value != null) { out.attribute(null, name, value); } }
private static void roundTrip(XmlPullParserFactory factory, String loc, String indent) throws XmlPullParserException, IOException { XmlPullParser pp = factory.newPullParser(); pp.setInput(new java.net.URL(loc).openStream(), null); XmlSerializer serializer = factory.newSerializer(); serializer.setOutput( System.out, null); if(indent != null) { serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent); } (new Roundtrip(pp, serializer)).roundTrip(); }
private String end() throws IOException { xmlSerializer.endTag(ns, "osm"); xmlSerializer.endDocument(); return stringWriter.toString(); }