本文整理汇总了Java中org.kxml2.kdom.Document.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java Document.addChild方法的具体用法?Java Document.addChild怎么用?Java Document.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.kdom.Document
的用法示例。
在下文中一共展示了Document.addChild方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateXmlManifestList
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
public void generateXmlManifestList(PrintWriter output, CallingContext cc) throws IOException, ODKDatastoreException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(HtmlConsts.UTF8_ENCODE);
Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.MANIFEST_TAG);
e.setPrefix(null, XML_TAG_NAMESPACE);
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
// build XML table of form information
BinaryContentManipulator manifest = form.getManifestFileset();
if ( manifest != null ) {
int fileCount = manifest.getAttachmentCount(cc);
for ( int i = 1 ; i <= fileCount ; ++i ) {
idx = generateManifestXmlEntry(d, e, idx, form.getUri(), manifest, i, cc);
}
}
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(output);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
}
示例2: generateXmlListOfForms
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
public void generateXmlListOfForms(PrintWriter output, CallingContext cc) throws IOException, ODKDatastoreException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(HtmlConsts.UTF8_ENCODE);
Element e = d.createElement(XML_TAG_NAMESPACE, XFormsTableConsts.XFORMS_TAG);
e.setPrefix(null, XML_TAG_NAMESPACE);
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
// build XML table of form information
for (IForm form : forms) {
if (!form.hasValidFormDefinition() || !form.getDownloadEnabled())
continue;
idx = generateFormXmlEntry(d, e, idx, form, cc);
}
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(output);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
}
示例3: emitXmlWrappedCsv
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
private void emitXmlWrappedCsv(List<Row> resultTable, List<String> headers) throws IOException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(HtmlConsts.UTF8_ENCODE);
Element e = d.createElement(XML_TAG_NAMESPACE, XML_TAG_ENTRIES);
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
if (websafeCursorString != null) {
Element cursor = d.createElement(XML_TAG_NAMESPACE, XML_TAG_CURSOR);
e.addChild(idx++, Node.ELEMENT, cursor);
cursor.addChild(0, Node.TEXT, websafeCursorString);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
}
Element header = d.createElement(XML_TAG_NAMESPACE, XML_TAG_HEADER);
e.addChild(idx++, Node.ELEMENT, header);
header.addChild(0, Node.TEXT, generateCommaSeperatedElements(headers));
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
Element resultRow;
// generate rows
for (Row row : resultTable) {
resultRow = d.createElement(XML_TAG_NAMESPACE, XML_TAG_RESULT);
e.addChild(idx++, Node.ELEMENT, resultRow);
String csvRow = generateCommaSeperatedElements(row.getFormattedValues());
resultRow.addChild(0, Node.TEXT, csvRow);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, BasicConsts.NEW_LINE);
}
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(output);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
}
示例4: generateInstanceSchema
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
public static Document generateInstanceSchema (FormDef f) {
init();
Element schema = new Element();
schema.setName("schema");
schema.setNamespace("http://www.w3.org/2001/XMLSchema");
schema.setPrefix("", "http://www.w3.org/2001/XMLSchema");
schema.setPrefix("jr", "http://openrosa.org/javarosa");
if (f.getInstance().schema != null) {
schema.setAttribute(null, "targetNamespace", f.getInstance().schema);
} else {
System.err.println("Warning: instance has no schema");
}
schema.setAttribute(null, "elementFormDefault", "qualified");
String formVersion = f.getInstance().formVersion;
String uiVersion = f.getInstance().uiVersion;
if (formVersion != null)
schema.setAttribute(null, "version", formVersion);
if (uiVersion != null)
schema.setAttribute(null, "uiVersion", uiVersion);
processSelectChoices(schema, f, f);
schema.addChild(Node.ELEMENT, schemizeInstance(f.getInstance().getRoot()));
Document schemaXML = new Document();
schemaXML.addChild(Node.ELEMENT, schema);
return schemaXML;
}
示例5: visit
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
public void visit(FormInstance tree) {
theXmlDoc = new Document();
//TreeElement root = tree.getRoot();
TreeElement root = tree.resolveReference(rootRef);
//For some reason resolveReference won't ever return the root, so we'll
//catch that case and just start at the root.
if(root == null) {
root = tree.getRoot();
}
if (root != null) {
theXmlDoc.addChild(Node.ELEMENT, serializeNode(root));
}
Element top = theXmlDoc.getElement(0);
String[] prefixes = tree.getNamespacePrefixes();
for(int i = 0 ; i < prefixes.length; ++i ) {
top.setPrefix(prefixes[i], tree.getNamespaceURI(prefixes[i]));
}
if (tree.schema != null) {
top.setNamespace(tree.schema);
top.setPrefix("", tree.schema);
}
}
示例6: createXmlRegistrationDoc
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
private Document createXmlRegistrationDoc(User u) {
Document document = new Document();
Element root = document.createElement(null,"registration");
root.setNamespace(XMLNS_UR);
addChildWithText(root,"username",u.getUsername());
addChildWithText(root,"password",u.getPasswordHash());
addChildWithText(root,"uuid",u.getUniqueId());
addChildWithText(root,"date",DateUtils.formatDate(new Date(),DateUtils.FORMAT_ISO8601));
addChildWithText(root, "registering_phone_id",PropertyManager._().getSingularProperty(JavaRosaPropertyRules.DEVICE_ID_PROPERTY));
Element userData = root.createElement(null,"user_data");
for(Enumeration en = u.listProperties(); en.hasMoreElements() ;) {
String property = (String)en.nextElement();
Element data= userData.createElement(null,"data");
data.setAttribute(null,"key",property);
data.addChild(Element.TEXT, u.getProperty(property));
userData.addChild(Element.ELEMENT, data);
}
root.addChild(Element.ELEMENT,userData);
document.addChild(Element.ELEMENT, root);
return document;
}
示例7: generateInstanceSchema
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
public static Document generateInstanceSchema (FormDef f) {
init();
Element schema = new Element();
schema.setName("schema");
schema.setNamespace("http://www.w3.org/2001/XMLSchema");
schema.setPrefix("", "http://www.w3.org/2001/XMLSchema");
schema.setPrefix("jr", "http://openrosa.org/javarosa");
if (f.getInstance().schema != null) {
schema.setAttribute(null, "targetNamespace", f.getInstance().schema);
} else {
System.err.println("Warning: instance has no schema");
}
schema.setAttribute(null, "elementFormDefault", "qualified");
String formVersion = f.getInstance().formVersion;
String uiVersion = f.getInstance().uiVersion;
if (formVersion != null)
schema.setAttribute(null, "version", formVersion);
if (uiVersion != null)
schema.setAttribute(null, "uiVersion", uiVersion);
processSelectChoices(schema, f, f);
schema.addChild(Node.ELEMENT, schemizeInstance(f.getInstance().getRoot()));
Document schemaXML = new Document();
schemaXML.addChild(Node.ELEMENT, schema);
return schemaXML;
}
示例8: visit
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
@Override
public void visit(FormInstance tree) {
theXmlDoc = new Document();
TreeElement root = tree.resolveReference(rootRef);
//For some reason resolveReference won't ever return the root, so we'll
//catch that case and just start at the root.
if (root == null) {
root = tree.getRoot();
}
if (root != null) {
theXmlDoc.addChild(Node.ELEMENT, serializeNode(root));
}
Element top = theXmlDoc.getElement(0);
String[] prefixes = tree.getNamespacePrefixes();
for (String prefix : prefixes) {
top.setPrefix(prefix, tree.getNamespaceURI(prefix));
}
if (tree.schema != null) {
top.setNamespace(tree.schema);
top.setPrefix("", tree.schema);
}
}
示例9: writeSubmissionManifest
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
private static void writeSubmissionManifest(
EncryptedFormInformation formInfo,
File submissionXml, List<File> mediaFiles) throws EncryptionException {
Document d = new Document();
d.setStandalone(true);
d.setEncoding(UTF_8);
Element e = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, DATA);
e.setPrefix(null, XML_ENCRYPTED_TAG_NAMESPACE);
e.setAttribute(null, ID, formInfo.formId);
if ( formInfo.formVersion != null ) {
e.setAttribute(null, VERSION, formInfo.formVersion);
}
e.setAttribute(null, ENCRYPTED, "yes");
d.addChild(0, Node.ELEMENT, e);
int idx = 0;
Element c;
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_KEY);
c.addChild(0, Node.TEXT, formInfo.base64RsaEncryptedSymmetricKey);
e.addChild(idx++, Node.ELEMENT, c);
c = d.createElement(XML_OPENROSA_NAMESPACE, META);
c.setPrefix("orx", XML_OPENROSA_NAMESPACE);
{
Element instanceTag = d.createElement(XML_OPENROSA_NAMESPACE, INSTANCE_ID);
instanceTag.addChild(0, Node.TEXT, formInfo.instanceMetadata.instanceId);
c.addChild(0, Node.ELEMENT, instanceTag);
}
e.addChild(idx++, Node.ELEMENT, c);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE);
if (mediaFiles != null) {
for (File file : mediaFiles) {
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, MEDIA);
Element fileTag = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, FILE);
fileTag.addChild(0, Node.TEXT, file.getName() + ".enc");
c.addChild(0, Node.ELEMENT, fileTag);
e.addChild(idx++, Node.ELEMENT, c);
e.addChild(idx++, Node.IGNORABLE_WHITESPACE, NEW_LINE);
}
}
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, ENCRYPTED_XML_FILE);
c.addChild(0, Node.TEXT, submissionXml.getName() + ".enc");
e.addChild(idx++, Node.ELEMENT, c);
c = d.createElement(XML_ENCRYPTED_TAG_NAMESPACE, BASE64_ENCRYPTED_ELEMENT_SIGNATURE);
c.addChild(0, Node.TEXT, formInfo.getBase64EncryptedElementSignature());
e.addChild(idx++, Node.ELEMENT, c);
FileOutputStream fout = null;
OutputStreamWriter writer = null;
try {
fout = new FileOutputStream(submissionXml);
writer = new OutputStreamWriter(fout, UTF_8);
KXmlSerializer serializer = new KXmlSerializer();
serializer.setOutput(writer);
// setting the response content type emits the xml header.
// just write the body here...
d.writeChildren(serializer);
serializer.flush();
writer.flush();
fout.getChannel().force(true);
writer.close();
} catch (Exception ex) {
ex.printStackTrace();
String msg = "Error writing submission.xml for encrypted submission: "
+ submissionXml.getParentFile().getName();
Log.e(t, msg);
throw new EncryptionException(msg, ex);
} finally {
IOUtils.closeQuietly(writer);
IOUtils.closeQuietly(fout);
}
}
示例10: parse
import org.kxml2.kdom.Document; //导入方法依赖的package包/类
@Override
public FormRecord parse() throws InvalidStructureException, IOException, XmlPullParserException {
String xmlns = parser.getNamespace();
//Parse this subdocument into a dom
Element element = new Element();
element.setName(parser.getName());
element.setNamespace(parser.getNamespace());
element.parse(this.parser);
//Consume the end tag.
//this.parser.next();
//create an actual document out of it.
Document document = new Document();
document.addChild(Node.ELEMENT, element);
KXmlSerializer serializer = new KXmlSerializer();
String filePath = getInstanceDestination(namespaceToInstallPath.get(xmlns));
//Register this instance for inspection
ContentValues values = new ContentValues();
values.put(InstanceColumns.DISPLAY_NAME, "Historical Form");
values.put(InstanceColumns.SUBMISSION_URI, "");
values.put(InstanceColumns.INSTANCE_FILE_PATH, filePath);
values.put(InstanceColumns.JR_FORM_ID, xmlns);
values.put(InstanceColumns.STATUS, InstanceProviderAPI.STATUS_COMPLETE);
values.put(InstanceColumns.CAN_EDIT_WHEN_COMPLETE, false);
// Unindexed flag tells content provider to link this instance to a
// new, unindexed form record that isn't attached to the
// AndroidSessionWrapper
values.put(InstanceProviderAPI.UNINDEXED_SUBMISSION, true);
Uri instanceRecord =
c.getContentResolver().insert(InstanceColumns.CONTENT_URI, values);
// Find the form record attached to the form instance during insertion
IStorageUtilityIndexed<FormRecord> storage = cachedStorage();
FormRecord attachedRecord =
storage.getRecordForValue(FormRecord.META_INSTANCE_URI,
instanceRecord.toString());
if (attachedRecord == null) {
throw new RuntimeException("No FormRecord was attached to the inserted form instance");
}
OutputStream o = new FileOutputStream(filePath);
BufferedOutputStream bos = null;
try {
Cipher encrypter = Cipher.getInstance("AES");
SecretKeySpec key = new SecretKeySpec(attachedRecord.getAesKey(), "AES");
encrypter.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(o, encrypter);
bos = new BufferedOutputStream(cos, 1024 * 256);
serializer.setOutput(bos, "UTF-8");
document.write(serializer);
} catch (InvalidKeyException | NoSuchPaddingException | NoSuchAlgorithmException e) {
// writing the form instance to xml failed, so remove the record
storage.remove(attachedRecord);
throw new RuntimeException(e.getMessage());
} finally {
//since bos might not have even been created.
if (bos != null) {
bos.close();
} else {
o.close();
}
}
return attachedRecord;
}