本文整理汇总了Java中org.kxml2.kdom.Element.getChildCount方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getChildCount方法的具体用法?Java Element.getChildCount怎么用?Java Element.getChildCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kxml2.kdom.Element
的用法示例。
在下文中一共展示了Element.getChildCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recurseForOutput
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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: parseIText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseIText (Element itext) {
Localizer l = new Localizer(true, true);
_f.setLocalizer(l);
l.registerLocalizable(_f);
ArrayList<String> usedAtts = new ArrayList<String>(); //used for warning message
for (int i = 0; i < itext.getChildCount(); i++) {
Element trans = itext.getElement(i);
if (trans == null || !trans.getName().equals("translation"))
continue;
parseTranslation(l, trans);
}
if (l.getAvailableLocales().length == 0)
throw new XFormParseException("no <translation>s defined",itext);
if (l.getDefaultLocale() == null)
l.setDefaultLocale(l.getAvailableLocales()[0]);
//print unused attribute warning message for parent element
if(XFormUtils.showUnusedAttributeWarning(itext, usedAtts)){
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(itext, usedAtts), getVagueLocation(itext));
}
}
示例3: getVagueElementPrintout
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
public static String getVagueElementPrintout(Element e, int maxDepth) {
String elementString = "<" + e.getName();
for(int i = 0; i < e.getAttributeCount() ; ++i) {
elementString += " " + e.getAttributeName(i) + "=\"";
elementString += e.getAttributeValue(i) + "\"";
}
if(e.getChildCount() > 0) {
elementString += ">";
if(e.getType(0) ==Element.ELEMENT) {
if(maxDepth > 0) {
elementString += getVagueElementPrintout((Element)e.getChild(0),maxDepth -1);
} else {
elementString += "...";
}
}
} else {
elementString += "/>";
}
return elementString;
}
示例4: parseUnregisteredSpecExtension
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
* Handle parsing and warning logic for a tag that doesn't have attached
* logic already, but has been registered as a spec extension.
*
* @param namespace String that is usually a url i.e. "http://opendatakit.org/xforms"
* @param name String representing tag name i.e. "extra" for an element like <extra ...>
* @param e is the current element we are parsing
* @param parent is the parent to the element we are parsing
* @param handlers maps tags to IElementHandlers, used to perform parsing of that tag
*/
public void parseUnregisteredSpecExtension(String namespace, String name, Element e, Object parent, Hashtable<String, IElementHandler> handlers) {
if (!XFormParser.suppressSpecExtensionWarnings.contains(namespace)) {
// raise a warning about not knowing how to parse
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP,
"Unrecognized element [" + name + "] from namespace " + namespace + ".",
getVagueLocation(e));
}
if (XFormParser.parseSpecExtensionsInnerElements.contains(namespace)) {
// parse inner elements using default parsing logic.
for (int i = 0; i < e.getChildCount(); i++) {
if (e.getType(i) == Element.ELEMENT) {
parseElement(e.getElement(i), parent, handlers);
}
}
}
}
示例5: getVagueElementPrintout
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
public static String getVagueElementPrintout(Element e, int maxDepth) {
String elementString = "<" + e.getName();
for (int i = 0; i < e.getAttributeCount(); ++i) {
elementString += " " + e.getAttributeName(i) + "=\"";
elementString += e.getAttributeValue(i) + "\"";
}
if (e.getChildCount() > 0) {
elementString += ">";
if (e.getType(0) == Element.ELEMENT) {
if (maxDepth > 0) {
elementString += getVagueElementPrintout((Element)e.getChild(0), maxDepth - 1);
} else {
elementString += "...";
}
}
} else {
elementString += "/>";
}
return elementString;
}
示例6: parseControlChildren
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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);
}
}
}
示例7: parseIText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseIText(Element itext) {
Localizer l = new Localizer(true, true);
_f.setLocalizer(l);
l.registerLocalizable(_f);
Vector<String> usedAtts = new Vector<String>(); //used for warning message
for (int i = 0; i < itext.getChildCount(); i++) {
Element trans = itext.getElement(i);
if (trans == null || !trans.getName().equals("translation"))
continue;
parseTranslation(l, trans);
}
if (l.getAvailableLocales().length == 0)
throw new XFormParseException("no <translation>s defined", itext);
if (l.getDefaultLocale() == null)
l.setDefaultLocale(l.getAvailableLocales()[0]);
//print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(itext, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(itext, usedAtts), getVagueLocation(itext));
}
}
示例8: parseIText
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseIText(Element itext) {
Localizer l = new Localizer(true, true);
_f.setLocalizer(l);
Vector<String> usedAtts = new Vector<>(); //used for warning message
for (int i = 0; i < itext.getChildCount(); i++) {
Element trans = itext.getElement(i);
if (trans == null || !trans.getName().equals("translation"))
continue;
parseTranslation(l, trans);
}
if (l.getAvailableLocales().length == 0)
throw new XFormParseException("no <translation>s defined", itext);
if (l.getDefaultLocale() == null)
l.setDefaultLocale(l.getAvailableLocales()[0]);
//print unused attribute warning message for parent element
if (XFormUtils.showUnusedAttributeWarning(itext, usedAtts)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP, XFormUtils.unusedAttWarning(itext, usedAtts), getVagueLocation(itext));
}
}
示例9: getChildElement
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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;
}
示例10: parseElement
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private void parseElement (Element e, Object parent, HashMap<String, IElementHandler> handlers) { //,
// boolean allowUnknownElements, boolean allowText, boolean recurseUnknown) {
String name = e.getName();
String[] suppressWarningArr = {
"html",
"head",
"body",
"xform",
"chooseCaption",
"addCaption",
"addEmptyCaption",
"delCaption",
"doneCaption",
"doneEmptyCaption",
"mainHeader",
"entryHeader",
"delHeader"
};
List<String> suppressWarning = new ArrayList<String>(suppressWarningArr.length);
for (int i = 0; i < suppressWarningArr.length; i++) {
suppressWarning.add(suppressWarningArr[i]);
}
IElementHandler eh = handlers.get(name);
if (eh != null) {
eh.handle(this, e, parent);
} else {
if (!suppressWarning.contains(name)) {
reporter.warning(XFormParserReporter.TYPE_UNKNOWN_MARKUP,
"Unrecognized element [" + name + "]. Ignoring and processing children...",
getVagueLocation(e));
}
for (int i = 0; i < e.getChildCount(); i++) {
if (e.getType(i) == Element.ELEMENT) {
parseElement(e.getElement(i), parent, handlers);
}
}
}
}
示例11: saveInstanceNode
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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);
}
示例12: getLabel
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
private String getLabel (Element e){
if(e.getChildCount() == 0) return null;
recurseForOutput(e);
StringBuilder sb = new StringBuilder();
for(int i = 0; i<e.getChildCount();i++){
if(e.getType(i)!=Node.TEXT && !(e.getChild(i) instanceof String)){
Object b = e.getChild(i);
Element child = (Element)b;
//If the child is in the HTML namespace, retain it.
if(NAMESPACE_HTML.equals(child.getNamespace())) {
sb.append(XFormSerializer.elementToString(child));
} else {
//Otherwise, ignore it.
System.out.println("Unrecognized tag inside of text: <" + child.getName() + ">. " +
"Did you intend to use HTML markup? If so, ensure that the element is defined in " +
"the HTML namespace.");
}
}else{
sb.append(e.getText(i));
}
}
String s = sb.toString().trim();
return s;
}
示例13: loadInstanceData
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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())));
}
}
}
示例14: recurseForOutput
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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;
}
}
}
示例15: saveInstanceNode
import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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);
}