use of org.xmlpull.v1.XmlPullParserFactory in project processdash by dtuma.
the class XmlParamDataPersisterV1 method getTextToPersistImpl.
private String getTextToPersistImpl(Map postedData) throws IOException {
XmlSerializer ser = null;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
ser = factory.newSerializer();
} catch (XmlPullParserException xppe) {
throw new RuntimeException("Couldn't obtain xml serializer", xppe);
}
try {
if (generateWhitespace)
ser.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
} catch (Exception e) {
}
StringWriter out = new StringWriter();
ser.setOutput(out);
ser.startDocument("utf-16", Boolean.TRUE);
ser.flush();
out.getBuffer().setLength(0);
ser.startTag(null, TOP_TAG);
// in "_ALL". This simplifies our work.
if (lenientPostedDataMode)
addMissingALLParams(postedData);
postedData = EditedPageDataParser.filterParamMap(postedData, new TreeMap(), null, "_ALL", false, true);
writeParamList(ser, postedData);
ser.endTag(null, TOP_TAG);
ser.endDocument();
return out.toString();
}
use of org.xmlpull.v1.XmlPullParserFactory in project processdash by dtuma.
the class TimeLogWriter method write.
public static void write(Writer out, Iterator timeLogEntries, boolean close) throws IOException {
XmlSerializer ser = null;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
ser = factory.newSerializer();
} catch (XmlPullParserException xppe) {
throw new RuntimeException("Couldn't obtain xml serializer", xppe);
}
ser.setOutput(out);
ser.startDocument(ENCODING, null);
ser.ignorableWhitespace(NEWLINE);
ser.startTag(null, DOC_ROOT_ELEM);
ser.ignorableWhitespace(NEWLINE);
try {
while (timeLogEntries.hasNext()) writeTimeLogEntry(ser, (TimeLogEntry) timeLogEntries.next());
} catch (IONoSuchElementException ionsee) {
throw ionsee.getIOException();
}
ser.endTag(null, DOC_ROOT_ELEM);
ser.ignorableWhitespace(NEWLINE);
ser.endDocument();
if (close)
out.close();
else
out.flush();
}
use of org.xmlpull.v1.XmlPullParserFactory in project processdash by dtuma.
the class DataExporterXMLv1 method writeDataElements.
private void writeDataElements(Writer out, HashTree sorted) throws IOException {
XmlSerializer xml = null;
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
xml = factory.newSerializer();
} catch (XmlPullParserException xppe) {
throw new RuntimeException("Couldn't obtain xml serializer", xppe);
}
// we need to write our header manually, because we need to specify
// XML version 1.1
out.write(DATA_XML_HEADER + NEWLINE + NEWLINE);
xml.setOutput(out);
xml.startTag(null, DATA_ELEM);
xml.ignorableWhitespace(NEWLINE);
writeDataElementsForNode(xml, sorted, 0);
xml.endTag(null, DATA_ELEM);
xml.ignorableWhitespace(NEWLINE);
xml.endDocument();
out.flush();
}
use of org.xmlpull.v1.XmlPullParserFactory in project coursera-android by aporter.
the class XMLResponseHandler method handleResponse.
@Override
public List<String> handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
try {
// Create the Pull Parser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
// Set the Parser's input to be the XML document in the HTTP Response
xpp.setInput(new InputStreamReader(response.getEntity().getContent()));
// Get the first Parser event and start iterating over the XML document
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
startTag(xpp.getName());
} else if (eventType == XmlPullParser.END_TAG) {
endTag(xpp.getName());
} else if (eventType == XmlPullParser.TEXT) {
text(xpp.getText());
}
eventType = xpp.next();
}
return mResults;
} catch (XmlPullParserException e) {
}
return null;
}
use of org.xmlpull.v1.XmlPullParserFactory in project android-maps-utils by googlemaps.
the class KmlLayer method createXmlParser.
/**
* Creates a new XmlPullParser to allow for the KML file to be parsed
*
* @param stream InputStream containing KML file
* @return XmlPullParser containing the KML file
* @throws XmlPullParserException if KML file cannot be parsed
*/
private static XmlPullParser createXmlParser(InputStream stream) throws XmlPullParserException {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
return parser;
}
Aggregations