本文整理汇总了Java中org.kxml2.kdom.Node.ELEMENT属性的典型用法代码示例。如果您正苦于以下问题:Java Node.ELEMENT属性的具体用法?Java Node.ELEMENT怎么用?Java Node.ELEMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.kxml2.kdom.Node
的用法示例。
在下文中一共展示了Node.ELEMENT属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recurseForOutput
private void recurseForOutput(Element e){
if(e.getChildCount() == 0) return;
for(int i=0;i<e.getChildCount();i++){
int kidType = e.getType(i);
if(kidType == Node.TEXT) { continue; }
if(e.getChild(i) instanceof String) { continue; }
Element kid = (Element)e.getChild(i);
//is just text
if(kidType == Node.ELEMENT && XFormUtils.isOutput(kid)){
String s = "${"+parseOutput(kid)+"}";
e.removeChild(i);
e.addChild(i, Node.TEXT, s);
//has kids? Recurse through them and swap output tag for parsed version
}else if(kid.getChildCount() !=0){
recurseForOutput(kid);
//is something else
}else{
continue;
}
}
}
示例2: parseControlChildren
private void parseControlChildren(Element e, QuestionDef question, IFormElement parent,
boolean isSelect) {
for (int i = 0; i < e.getChildCount(); i++) {
int type = e.getType(i);
Element child = (type == Node.ELEMENT ? e.getElement(i) : null);
if (child == null) {
continue;
}
String childName = child.getName();
if (LABEL_ELEMENT.equals(childName) || HINT_ELEMENT.equals(childName)
|| HELP_ELEMENT.equals(childName) || CONSTRAINT_ELEMENT.equals(childName)) {
parseHelperText(question, child);
} else if (isSelect && "item".equals(childName)) {
parseItem(question, child);
} else if (isSelect && "itemset".equals(childName)) {
parseItemset(question, child);
} else if (actionHandlers.containsKey(childName)) {
actionHandlers.get(childName).handle(this, child, question);
}
}
}
示例3: getChildElement
private static Element getChildElement(Element parent, String childName) {
Element e = null;
int c = parent.getChildCount();
int i = 0;
for (i = 0; i < c; i++) {
if (parent.getType(i) == Node.ELEMENT) {
if (parent.getElement(i).getName().equalsIgnoreCase(childName)) {
return parent.getElement(i);
}
}
}
return e;
}
示例4: saveInstanceNode
private void saveInstanceNode (Element instance) {
Element instanceNode = null;
String instanceId = instance.getAttributeValue("", "id");
for (int i = 0; i < instance.getChildCount(); i++) {
if (instance.getType(i) == Node.ELEMENT) {
if (instanceNode != null) {
throw new XFormParseException("XForm Parse: <instance> has more than one child element", instance);
} else {
instanceNode = instance.getElement(i);
}
}
}
if(instanceNode == null) {
//no kids
instanceNode = instance;
}
if (mainInstanceNode == null) {
mainInstanceNode = instanceNode;
}
instanceNodes.add(instanceNode);
instanceNodeIdStrs.add(instanceId);
}
示例5: loadInstanceData
private static void loadInstanceData (Element node, TreeElement cur, FormDef f) {
int numChildren = node.getChildCount();
boolean hasElements = false;
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
hasElements = true;
break;
}
}
if (hasElements) {
HashMap<String, Integer> multiplicities = new HashMap<String, Integer>(); //stores max multiplicity seen for a given node name thus far
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
Element child = node.getElement(i);
String name = child.getName();
int index;
boolean isTemplate = (child.getAttributeValue(NAMESPACE_JAVAROSA, "template") != null);
if (isTemplate) {
index = TreeReference.INDEX_TEMPLATE;
} else {
//update multiplicity counter
Integer mult = multiplicities.get(name);
index = (mult == null ? 0 : mult.intValue() + 1);
multiplicities.put(name, Integer.valueOf(index));
}
loadInstanceData(child, cur.getChild(name, index), f);
}
}
} else {
String text = getXMLText(node, true);
if (text != null && text.trim().length() > 0) { //ignore text that is only whitespace
//TODO: custom data types? modelPrototypes?
cur.setValue(XFormAnswerDataParser.getAnswerData(text, cur.getDataType(), ghettoGetQuestionDef(cur.getDataType(), f, cur.getRef())));
}
}
}
示例6: saveInstanceNode
private void saveInstanceNode(Element instance) {
Element instanceNode = null;
String instanceId = instance.getAttributeValue("", "id");
for (int i = 0; i < instance.getChildCount(); i++) {
if (instance.getType(i) == Node.ELEMENT) {
if (instanceNode != null) {
throw new XFormParseException("XForm Parse: <instance> has more than one child element", instance);
} else {
instanceNode = instance.getElement(i);
}
}
}
if (instanceNode == null) {
//no kids
instanceNode = instance;
}
if (mainInstanceNode == null) {
mainInstanceNode = instanceNode;
} else if (instanceId == null) {
throw new XFormParseException("XForm Parse: Non-main <instance> element requires an id attribute", instance);
}
instanceNodes.addElement(instanceNode);
instanceNodeIdStrs.addElement(instanceId);
}
示例7: recurseForOutput
private void recurseForOutput(Element e) {
if (e.getChildCount() == 0) return;
for (int i = 0; i < e.getChildCount(); i++) {
int kidType = e.getType(i);
if (kidType == Node.TEXT) {
continue;
}
if (e.getChild(i) instanceof String) {
continue;
}
Element kid = (Element)e.getChild(i);
//is just text
if (kidType == Node.ELEMENT && XFormUtils.isOutput(kid)) {
String s = "${" + parseOutput(kid) + "}";
e.removeChild(i);
e.addChild(i, Node.TEXT, s);
//has kids? Recurse through them and swap output tag for parsed version
} else if (kid.getChildCount() != 0) {
recurseForOutput(kid);
//is something else
} else {
continue;
}
}
}
示例8: loadInstanceData
/**
* Traverse the node, copying data from it into the TreeElement argument.
*
* @param node Parsed XML for a form instance
* @param cur Valueless structure of the form instance, which will have
* values copied in by this method
*/
private static void loadInstanceData(Element node, TreeElement cur) {
// TODO: hook here for turning sub-trees into complex IAnswerData
// objects (like for immunizations)
// FIXME: the 'ref' and FormDef parameters (along with the helper
// function above that initializes them) are only needed so that we can
// fetch QuestionDefs bound to the given node, as the QuestionDef
// reference is needed to properly represent answers to select
// questions. obviously, we want to fix this.
int numChildren = node.getChildCount();
boolean hasElements = false;
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
hasElements = true;
break;
}
}
if (hasElements) {
// recur on child nodes
// stores max multiplicity seen for a given node name thus far
Hashtable<String, Integer> multiplicities = new Hashtable<String, Integer>();
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
Element child = node.getElement(i);
String name = child.getName();
int index;
boolean isTemplate = (child.getAttributeValue(NAMESPACE_JAVAROSA, "template") != null);
if (isTemplate) {
index = TreeReference.INDEX_TEMPLATE;
} else {
//update multiplicity counter
Integer mult = multiplicities.get(name);
index = (mult == null ? 0 : mult.intValue() + 1);
multiplicities.put(name, DataUtil.integer(index));
}
loadInstanceData(child, cur.getChild(name, index));
}
}
} else {
// copy values from node into current tree element
String text = getXMLText(node, true);
if (text != null && text.trim().length() > 0) {
// ignore text that is only whitespace
// TODO: custom data types? modelPrototypes?
cur.setValue(AnswerDataFactory.templateByDataType(cur.getDataType()).cast(new UncastData(text.trim())));
}
}
}
示例9: parseItemset
private void parseItemset(QuestionDef q, Element e) {
ItemsetBinding itemset = new ItemsetBinding();
////////////////USED FOR PARSER WARNING OUTPUT ONLY
//catalogue of used attributes in this method/element
Vector<String> usedAtts = new Vector<>();
Vector<String> labelUA = new Vector<>(); //for child with name 'label'
Vector<String> valueUA = new Vector<>(); //for child with name 'value'
Vector<String> copyUA = new Vector<>(); //for child with name 'copy'
usedAtts.addElement(NODESET_ATTR);
labelUA.addElement(REF_ATTR);
valueUA.addElement(REF_ATTR);
valueUA.addElement(FORM_ATTR);
copyUA.addElement(REF_ATTR);
////////////////////////////////////////////////////
String nodesetStr = e.getAttributeValue("", NODESET_ATTR);
if (nodesetStr == null) {
throw new RuntimeException("No nodeset attribute in element: [" + e.getName() + "]. This is required. (Element Printout:" + XFormSerializer.elementToString(e) + ")");
}
XPathPathExpr path = XPathReference.getPathExpr(nodesetStr);
itemset.nodesetExpr = new XPathConditional(path);
itemset.contextRef = getFormElementRef(q);
itemset.nodesetRef = FormInstance.unpackReference(getAbsRef(new XPathReference(path.getReference()), itemset.contextRef));
for (int i = 0; i < e.getChildCount(); i++) {
int type = e.getType(i);
Element child = (type == Node.ELEMENT ? e.getElement(i) : null);
String childName = (child != null ? child.getName() : null);
if (LABEL_ELEMENT.equals(childName)) {
parseItemsetLabelElement(child, itemset, labelUA);
} else if ("copy".equals(childName)) {
parseItemsetCopyElement(child, itemset, copyUA);
} else if (VALUE.equals(childName)) {
parseItemsetValueElement(child, itemset, valueUA);
} else if (SORT.equals(childName)) {
parseItemsetSortElement(child, itemset);
}
}
if (itemset.labelRef == null) {
throw new XFormParseException("<itemset> requires <label>");
} else if (itemset.copyRef == null && itemset.valueRef == null) {
throw new XFormParseException("<itemset> requires <copy> or <value>");
}
if (itemset.copyRef != null) {
if (itemset.valueRef == null) {
reporter.warning(XFormParserReporter.TYPE_TECHNICAL, "<itemset>s with <copy> are STRONGLY recommended to have <value> as well; pre-selecting, default answers, and display of answers will not work properly otherwise", getVagueLocation(e));
} else if (!itemset.copyRef.isParentOf(itemset.valueRef, false)) {
throw new XFormParseException("<value> is outside <copy>");
}
}
q.setDynamicChoices(itemset);
itemsets.addElement(itemset);
if (XFormUtils.showUnusedAttributeWarning(e, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(e, usedAtts), getVagueLocation(e));
}
}
示例10: buildInstanceStructure
/** parse instance hierarchy and turn into a skeleton model; ignoring data content, but respecting repeated nodes and 'template' flags */
public static TreeElement buildInstanceStructure(Element node, TreeElement parent, String instanceName, String docnamespace) {
TreeElement element = null;
//catch when text content is mixed with children
int numChildren = node.getChildCount();
boolean hasText = false;
boolean hasElements = false;
for (int i = 0; i < numChildren; i++) {
switch (node.getType(i)) {
case Node.ELEMENT:
hasElements = true;
break;
case Node.TEXT:
if (node.getText(i).trim().length() > 0)
hasText = true;
break;
}
}
if (hasElements && hasText) {
System.out.println("Warning: instance node '" + node.getName() + "' contains both elements and text as children; text ignored");
}
//check for repeat templating
String name = node.getName();
int multiplicity;
if (node.getAttributeValue(NAMESPACE_JAVAROSA, "template") != null) {
multiplicity = TreeReference.INDEX_TEMPLATE;
if (parent != null && parent.getChild(name, TreeReference.INDEX_TEMPLATE) != null) {
throw new XFormParseException("More than one node declared as the template for the same repeated set [" + name + "]", node);
}
} else {
multiplicity = (parent == null ? 0 : parent.getChildMultiplicity(name));
}
String modelType = node.getAttributeValue(NAMESPACE_JAVAROSA, "modeltype");
//create node; handle children
if (modelType == null) {
element = new TreeElement(name, multiplicity);
element.setInstanceName(instanceName);
} else {
if (typeMappings.get(modelType) == null) {
throw new XFormParseException("ModelType " + modelType + " is not recognized.", node);
}
element = new TreeElement(name, multiplicity);
}
if (node.getNamespace() != null) {
if (!node.getNamespace().equals(docnamespace)) {
element.setNamespace(node.getNamespace());
}
}
if (hasElements) {
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
element.addChild(buildInstanceStructure(node.getElement(i), element, instanceName, docnamespace));
}
}
}
//handle attributes
if (node.getAttributeCount() > 0) {
for (int i = 0; i < node.getAttributeCount(); i++) {
String attrNamespace = node.getAttributeNamespace(i);
String attrName = node.getAttributeName(i);
if (attrNamespace.equals(NAMESPACE_JAVAROSA) && attrName.equals("template")) {
continue;
}
if (attrNamespace.equals(NAMESPACE_JAVAROSA) && attrName.equals("recordset")) {
continue;
}
element.setAttribute(attrNamespace, attrName, node.getAttributeValue(i));
}
}
return element;
}
示例11: loadInstanceData
/**
* Traverse the node, copying data from it into the TreeElement argument.
*
* @param node Parsed XML for a form instance
* @param cur Valueless structure of the form instance, which will have
* values copied in by this method
*/
private static void loadInstanceData(Element node, TreeElement cur) {
// TODO: hook here for turning sub-trees into complex IAnswerData
// objects (like for immunizations)
// FIXME: the 'ref' and FormDef parameters (along with the helper
// function above that initializes them) are only needed so that we can
// fetch QuestionDefs bound to the given node, as the QuestionDef
// reference is needed to properly represent answers to select
// questions. obviously, we want to fix this.
int numChildren = node.getChildCount();
boolean hasElements = false;
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
hasElements = true;
break;
}
}
if (hasElements) {
// recur on child nodes
// stores max multiplicity seen for a given node name thus far
Hashtable<String, Integer> multiplicities = new Hashtable<>();
for (int i = 0; i < numChildren; i++) {
if (node.getType(i) == Node.ELEMENT) {
Element child = node.getElement(i);
String name = child.getName();
int index;
boolean isTemplate = (child.getAttributeValue(NAMESPACE_JAVAROSA, "template") != null);
if (isTemplate) {
index = TreeReference.INDEX_TEMPLATE;
} else {
//update multiplicity counter
Integer mult = multiplicities.get(name);
index = (mult == null ? 0 : mult + 1);
multiplicities.put(name, DataUtil.integer(index));
}
loadInstanceData(child, cur.getChild(name, index));
}
}
} else {
// copy values from node into current tree element
String text = getXMLText(node, true);
if (text != null && text.trim().length() > 0) {
// ignore text that is only whitespace
// TODO: custom data types? modelPrototypes?
cur.setValue(AnswerDataFactory.templateByDataType(cur.getDataType()).cast(new UncastData(text.trim())));
}
}
}