当前位置: 首页>>代码示例>>Java>>正文


Java Element.setAttribute方法代码示例

本文整理汇总了Java中org.kxml2.kdom.Element.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Element.setAttribute方法的具体用法?Java Element.setAttribute怎么用?Java Element.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kxml2.kdom.Element的用法示例。


在下文中一共展示了Element.setAttribute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseBind

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
protected void parseBind(Element e) {
  // remember raw bindings in case we want to compare parsed XForms later
  parser.bindElements.add(copyBindingElement(e));
  List<String> usedAtts = new ArrayList<String>();

  DataBinding binding = processStandardBindAttributes(usedAtts, e);

  String value = e.getAttributeValue(ParserConsts.NAMESPACE_ODK, "length");
  if (value != null) {
    e.setAttribute(ParserConsts.NAMESPACE_ODK, "length", null);
  }

  log.info("Calling handle found value " + ((value == null) ? "null" : value));

  if (value != null) {
    Integer iValue = Integer.valueOf(value);
    parser.setNodesetStringLength(e.getAttributeValue(null, "nodeset"), iValue);
  }

  // print unused attribute warning message for parent element
  if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
    System.out.println(XFormUtils.unusedAttWarning(e, usedAtts));
  }

  addBinding(binding);
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:27,代码来源:BaseFormParserForJavaRosa.java

示例2: writeChoices

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static void writeChoices (Element e, String typeName, List<SelectChoice> choices) {
	Element st = new Element();
	st.setName("simpleType");
	st.setAttribute(null, "name", typeName);
	e.addChild(Node.ELEMENT, st);

	Element restr = new Element();
	restr.setName("restriction");
	restr.setAttribute(null, "base", "string");
	st.addChild(Node.ELEMENT, restr);

	for (int i = 0; i < choices.size(); i++) {
		String value = choices.get(i).getValue();

		Element choice = new Element();
		choice.setName("enumeration");
		choice.setAttribute(null, "value", value);
		restr.addChild(Node.ELEMENT, choice);
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:21,代码来源:InstanceSchema.java

示例3: writeChoices

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static void writeChoices (Element e, String typeName, Vector<SelectChoice> choices) {
    Element st = new Element();
    st.setName("simpleType");
    st.setAttribute(null, "name", typeName);
    e.addChild(Node.ELEMENT, st);

    Element restr = new Element();
    restr.setName("restriction");
    restr.setAttribute(null, "base", "string");
    st.addChild(Node.ELEMENT, restr);

    for (int i = 0; i < choices.size(); i++) {
        String value = choices.elementAt(i).getValue();

        Element choice = new Element();
        choice.setName("enumeration");
        choice.setAttribute(null, "value", value);
        restr.addChild(Node.ELEMENT, choice);
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:21,代码来源:InstanceSchema.java

示例4: addSecurityHeader

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
void addSecurityHeader(SoapSerializationEnvelope envelope){
    Element headers[] = new Element[1];
    headers[0]= new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
    headers[0].setAttribute(envelope.env, "mustUnderstand", "1");
    Element security=headers[0];

    Element token = new Element().createElement(security.getNamespace(), "UsernameToken");
    token.setAttribute("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "UsernameToken-2");

    Element username = new Element().createElement(security.getNamespace(), "Username");
    username.addChild(Node.TEXT, USERNAME);
    token.addChild(Node.ELEMENT,username);

    Element password = new Element().createElement(security.getNamespace(), "Password");
    password.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
    password.addChild(Node.TEXT, USERPASSWORD);
    token.addChild(Node.ELEMENT,password);
    
    headers[0].addChild(Node.ELEMENT, token);

    envelope.headerOut = headers;
}
 
开发者ID:mmprog,项目名称:wspocztapolska,代码行数:23,代码来源:WSPoczta.java

示例5: copyBindingElement

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static Element copyBindingElement(Element element) {
  Element retval = new Element();
  retval.createElement(element.getNamespace(), element.getName());
  for (int i = 0; i < element.getAttributeCount(); i++) {
    retval.setAttribute(element.getAttributeNamespace(i), element.getAttributeName(i),
        element.getAttributeValue(i));
  }
  return (retval);
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:10,代码来源:BaseFormParserForJavaRosa.java

示例6: 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;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:31,代码来源:InstanceSchema.java

示例7: writeListType

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static void writeListType (Element e, String typeName) {
	Element st = new Element();
	st.setName("simpleType");
	st.setAttribute(null, "name", "list." + typeName);
	e.addChild(Node.ELEMENT, st);

	Element list = new Element();
	list.setName("list");
	list.setAttribute(null, "itemType", typeName);
	st.addChild(Node.ELEMENT, list);
}
 
开发者ID:medic,项目名称:javarosa,代码行数:12,代码来源:InstanceSchema.java

示例8: 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;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:29,代码来源:HttpUserRegistrationTranslator.java

示例9: serializeLog

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private Element serializeLog(LogEntry log) {
    Element entry = new Element();
    entry.setName("log");
    entry.setAttribute(null, "date", DateUtils.formatDateTime(log.getTime(), DateUtils.FORMAT_ISO8601));

    Element type = entry.createElement(null,"type");
    type.addChild(Element.TEXT, log.getType());
    entry.addChild(Element.ELEMENT, type);

    Element message = entry.createElement(null,"msg");
    message.addChild(Element.TEXT, log.getMessage());
    entry.addChild(Element.ELEMENT, message);

    return entry;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:16,代码来源:XmlLogSerializer.java

示例10: 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;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:31,代码来源:InstanceSchema.java

示例11: writeListType

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static void writeListType (Element e, String typeName) {
    Element st = new Element();
    st.setName("simpleType");
    st.setAttribute(null, "name", "list." + typeName);
    e.addChild(Node.ELEMENT, st);

    Element list = new Element();
    list.setName("list");
    list.setAttribute(null, "itemType", typeName);
    st.addChild(Node.ELEMENT, list);
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:12,代码来源:InstanceSchema.java

示例12: writeSubmissionManifest

import org.kxml2.kdom.Element; //导入方法依赖的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);
      }
  }
 
开发者ID:Last-Mile-Health,项目名称:ODK-Liberia,代码行数:78,代码来源:EncryptionUtils.java

示例13: schemizeInstance

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static Element schemizeInstance (TreeElement node) {
	String name = node.getName();
	boolean terminal = node.isLeaf();
	boolean repeatable = node.isRepeatable();

	if (repeatable && node.getMult() != TreeReference.INDEX_TEMPLATE) {
		return null;
	}

	Element e = new Element();
	e.setName("element");
	e.setAttribute(null, "name", name);
	e.setAttribute(null, "minOccurs", "0"); //technically only needed if node has a 'relevant' attribute bound to it, but no easy way to tell
	if (repeatable) {
		e.setAttribute(null, "maxOccurs", "unbounded");
	}

	if (!terminal) {
		Element ct = new Element();
		ct.setName("complexType");
		e.addChild(Node.ELEMENT, ct);

		Element seq = new Element();
		seq.setName("sequence");
		ct.addChild(Node.ELEMENT, seq);

		for (int i = 0; i < node.getNumChildren(); i++) {
			Element child = schemizeInstance((TreeElement)node.getChildAt(i));
			if (child != null) {
				seq.addChild(Node.ELEMENT, child);
			}
		}
	} else {
		String type;

		switch (node.getDataType()) {
		case Constants.DATATYPE_NULL:
		case Constants.DATATYPE_TEXT:
			type = "string";
			break;
		case Constants.DATATYPE_INTEGER: type = "integer"; break;
		case Constants.DATATYPE_LONG: type = "long"; break;
		case Constants.DATATYPE_DECIMAL: type = "decimal"; break;
		case Constants.DATATYPE_BOOLEAN: type = "boolean"; break;
		case Constants.DATATYPE_DATE: type = "date"; break;
		case Constants.DATATYPE_DATE_TIME: type = "dateTime"; break;
		case Constants.DATATYPE_TIME: type = "time"; break;
		case Constants.DATATYPE_CHOICE:
		case Constants.DATATYPE_CHOICE_LIST:
			type = (String)choiceTypeMapping.get(node);
			if (type == null) {
				System.err.println("can't find choices for select-type question [" + node.getName() + "]");
			}
			break;
		case Constants.DATATYPE_GEOPOINT: type = "jr:geopoint"; break;
		case Constants.DATATYPE_GEOSHAPE: type = "jr:geoshape"; break;
		case Constants.DATATYPE_GEOTRACE: type = "jr:geotrace"; break;
		default:
			type = null;
			System.err.println("unrecognized type [" + node.getDataType() + ";" + node.getName() + "]");
			break;
		}

		if (type != null) {
			e.setAttribute(null, "type", type);
		}
	}

	return e;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:71,代码来源:InstanceSchema.java

示例14: schemizeInstance

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private static Element schemizeInstance (TreeElement node) {
    String name = node.getName();
    boolean terminal = node.isLeaf();
    boolean repeatable = node.isRepeatable();

    if (repeatable && node.getMult() != TreeReference.INDEX_TEMPLATE) {
        return null;
    }

    Element e = new Element();
    e.setName("element");
    e.setAttribute(null, "name", name);
    e.setAttribute(null, "minOccurs", "0"); //technically only needed if node has a 'relevant' attribute bound to it, but no easy way to tell
    if (repeatable) {
        e.setAttribute(null, "maxOccurs", "unbounded");
    }

    if (!terminal) {
        Element ct = new Element();
        ct.setName("complexType");
        e.addChild(Node.ELEMENT, ct);

        Element seq = new Element();
        seq.setName("sequence");
        ct.addChild(Node.ELEMENT, seq);

        for (int i = 0; i < node.getNumChildren(); i++) {
            Element child = schemizeInstance(node.getChildAt(i));
            if (child != null) {
                seq.addChild(Node.ELEMENT, child);
            }
        }
    } else {
        String type;

        switch (node.getDataType()) {
        case Constants.DATATYPE_NULL:
        case Constants.DATATYPE_TEXT:
            type = "string";
            break;
        case Constants.DATATYPE_INTEGER: type = "integer"; break;
        case Constants.DATATYPE_LONG: type = "long"; break;
        case Constants.DATATYPE_DECIMAL: type = "decimal"; break;
        case Constants.DATATYPE_BOOLEAN: type = "boolean"; break;
        case Constants.DATATYPE_DATE: type = "date"; break;
        case Constants.DATATYPE_DATE_TIME: type = "dateTime"; break;
        case Constants.DATATYPE_TIME: type = "time"; break;
        case Constants.DATATYPE_CHOICE:
        case Constants.DATATYPE_CHOICE_LIST:
            type = (String)choiceTypeMapping.get(node);
            if (type == null) {
                System.err.println("can't find choices for select-type question [" + node.getName() + "]");
            }
            break;
        case Constants.DATATYPE_GEOPOINT: type = "jr:geopoint"; break;
        default:
            type = null;
            System.err.println("unrecognized type [" + node.getDataType() + ";" + node.getName() + "]");
            break;
        }

        if (type != null) {
            e.setAttribute(null, "type", type);
        }
    }

    return e;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:69,代码来源:InstanceSchema.java


注:本文中的org.kxml2.kdom.Element.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。