use of org.kxml2.kdom.Document in project javarosa by opendatakit.
the class XFormParser method restoreDataModel.
public static FormInstance restoreDataModel(Document doc, Class restorableType) {
Restorable r = (restorableType != null ? (Restorable) PrototypeFactory.getInstance(restorableType) : null);
Element e = doc.getRootElement();
TreeElement te = buildInstanceStructure(e, null, buildNamespacesMap(e), null);
FormInstance dm = new FormInstance(te);
loadNamespaces(e, dm);
if (r != null) {
RestoreUtils.templateData(r, dm, null);
}
loadInstanceData(e, te, null);
return dm;
}
use of org.kxml2.kdom.Document in project javarosa by opendatakit.
the class XFormSerializer method getStream.
public static ByteArrayOutputStream getStream(Document doc) {
KXmlSerializer serializer = new KXmlSerializer();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
try {
serializer.setOutput(dos, null);
doc.write(serializer);
serializer.flush();
return bos;
} catch (Exception e) {
Std.printStack(e);
return null;
}
}
use of org.kxml2.kdom.Document in project javarosa by opendatakit.
the class ElementParser method instantiateParser.
/**
* Prepares a parser that will be used by the element parser, configuring relevant
* parameters and setting it to the appropriate point in the document.
*
* @param stream A stream which is reading the XML content
* of the document.
* @throws IOException If the stream cannot be read for any reason
* other than invalid XML Structures.
*/
public static KXmlParser instantiateParser(InputStream stream) throws IOException {
KXmlParser parser = new KXmlParser();
try {
parser.setInput(stream, "UTF-8");
parser.setFeature(KXmlParser.FEATURE_PROCESS_NAMESPACES, true);
// Point to the first available tag.
parser.next();
return parser;
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
Logger.exception("Element Parser", e);
throw new IOException(e.getMessage());
} catch (IllegalArgumentException e) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
Aggregations