本文整理汇总了Java中org.kxml2.kdom.Element.setNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java Element.setNamespace方法的具体用法?Java Element.setNamespace怎么用?Java Element.setNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.kdom.Element
的用法示例。
在下文中一共展示了Element.setNamespace方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateInstanceSchema
import org.kxml2.kdom.Element; //导入方法依赖的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;
}
示例2: visit
import org.kxml2.kdom.Element; //导入方法依赖的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);
}
}
示例3: createXmlRegistrationDoc
import org.kxml2.kdom.Element; //导入方法依赖的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;
}
示例4: generateInstanceSchema
import org.kxml2.kdom.Element; //导入方法依赖的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.Element; //导入方法依赖的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);
}
}
示例6: parse
import org.kxml2.kdom.Element; //导入方法依赖的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;
}