Java Code Examples for org.xmlpull.v1.XmlSerializer#setPrefix()
The following examples show how to use
org.xmlpull.v1.XmlSerializer#setPrefix() .
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: SerializerExample.java From exificient with MIT License | 6 votes |
static void write(XmlSerializer xpp) throws IllegalArgumentException, IllegalStateException, IOException { xpp.startDocument(null, null); xpp.setPrefix("foo", "urn:foo"); // first prefix xpp.startTag("", "root"); xpp.attribute("", "atRoot", "atValue"); { xpp.comment("my comment"); xpp.startTag("", "el1"); xpp.text("el1 text"); xpp.endTag("", "el1"); } xpp.endTag("", "root"); xpp.endDocument(); }
Example 2
Source File: FormulaList.java From microMathematics with GNU General Public License v3.0 | 5 votes |
/** * 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 3
Source File: XmlMapsGDataSerializer.java From mytracks with Apache License 2.0 | 5 votes |
private final void declareEntryNamespaces(XmlSerializer serializer) throws IOException { serializer.setPrefix( "" /* default ns */, XmlGDataParser.NAMESPACE_ATOM_URI); serializer.setPrefix( XmlGDataParser.NAMESPACE_GD, XmlGDataParser.NAMESPACE_GD_URI); declareExtraEntryNamespaces(serializer); }
Example 4
Source File: XmlMapsGDataSerializer.java From mytracks with Apache License 2.0 | 5 votes |
@Override protected void serializeExtraEntryContents(XmlSerializer serializer, int format) throws IOException { Map<String, String> attrs = entry.getAllAttributes(); for (Map.Entry<String, String> attr : attrs.entrySet()) { serializer.startTag("http://schemas.google.com/g/2005", "customProperty"); serializer.attribute(null, "name", attr.getKey()); serializer.text(attr.getValue()); serializer.endTag("http://schemas.google.com/g/2005", "customProperty"); } String privacy = entry.getPrivacy(); if (!StringUtils.isEmpty(privacy)) { serializer.setPrefix("app", APP_NAMESPACE); if ("public".equals(privacy)) { serializer.startTag(APP_NAMESPACE, "control"); serializer.startTag(APP_NAMESPACE, "draft"); serializer.text("no"); serializer.endTag(APP_NAMESPACE, "draft"); serializer.endTag(APP_NAMESPACE, "control"); } if ("unlisted".equals(privacy)) { serializer.startTag(APP_NAMESPACE, "control"); serializer.startTag(APP_NAMESPACE, "draft"); serializer.text("yes"); serializer.endTag(APP_NAMESPACE, "draft"); serializer.endTag(APP_NAMESPACE, "control"); } } }
Example 5
Source File: XmlNamespaceDictionary.java From google-http-java-client with Apache License 2.0 | 5 votes |
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); }
Example 6
Source File: KmlFiles.java From Androzic with GNU General Public License v3.0 | 4 votes |
/** * 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: GpxFiles.java From Androzic with GNU General Public License v3.0 | 4 votes |
/** * 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 { 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("", GPX_NAMESPACE); serializer.startTag(GPX_NAMESPACE, GpxParser.GPX); serializer.attribute("", "creator", "Androzic http://androzic.com"); serializer.startTag(GPX_NAMESPACE, GpxParser.TRK); serializer.startTag(GPX_NAMESPACE, GpxParser.NAME); serializer.text(track.name); serializer.endTag(GPX_NAMESPACE, GpxParser.NAME); serializer.startTag(GPX_NAMESPACE, GpxParser.SRC); serializer.text(Androzic.getDeviceName()); serializer.endTag(GPX_NAMESPACE, GpxParser.SRC); boolean first = true; serializer.startTag(GPX_NAMESPACE, GpxParser.TRKSEG); List<TrackPoint> trackPoints = track.getAllPoints(); for (TrackPoint tp : trackPoints) { if (!tp.continous && !first) { serializer.endTag(GPX_NAMESPACE, GpxParser.TRKSEG); serializer.startTag(GPX_NAMESPACE, GpxParser.TRKSEG); } serializer.startTag(GPX_NAMESPACE, GpxParser.TRKPT); serializer.attribute("", GpxParser.LAT, String.valueOf(tp.latitude)); serializer.attribute("", GpxParser.LON, String.valueOf(tp.longitude)); serializer.startTag(GPX_NAMESPACE, GpxParser.ELE); serializer.text(String.valueOf(tp.elevation)); serializer.endTag(GPX_NAMESPACE, GpxParser.ELE); serializer.startTag(GPX_NAMESPACE, GpxParser.TIME); serializer.text(GpxParser.trktime.format(new Date(tp.time))); serializer.endTag(GPX_NAMESPACE, GpxParser.TIME); serializer.endTag(GPX_NAMESPACE, GpxParser.TRKPT); first = false; } serializer.endTag(GPX_NAMESPACE, GpxParser.TRKSEG); serializer.endTag(GPX_NAMESPACE, GpxParser.TRK); serializer.endTag(GPX_NAMESPACE, GpxParser.GPX); serializer.endDocument(); serializer.flush(); writer.close(); }