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


Java Node.TEXT属性代码示例

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


在下文中一共展示了Node.TEXT属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
		}
	}
}
 
开发者ID:medic,项目名称:javarosa,代码行数:24,代码来源:XFormParser.java

示例2: getXMLText

/**
* reads all subsequent text nodes and returns the combined string
* needed because escape sequences are parsed into consecutive text nodes
* e.g. "abc&amp;123" --> (abc)(&)(123)
**/
public static String getXMLText (Node node, int i, boolean trim) {
	StringBuilder strBuff = null;

	String text = node.getText(i);
	if (text == null)
		return null;

	for (i++; i < node.getChildCount() && node.getType(i) == Node.TEXT; i++) {
		if (strBuff == null)
			strBuff = new StringBuilder(text);

		strBuff.append(node.getText(i));
	}
	if (strBuff != null)
		text = strBuff.toString();

	if (trim)
		text = text.trim();

	return text;
}
 
开发者ID:medic,项目名称:javarosa,代码行数:26,代码来源:XFormParser.java

示例3: getXMLText

/**
 * reads all subsequent text nodes and returns the combined string
 * needed because escape sequences are parsed into consecutive text nodes
 * e.g. "abc&amp;123" --> (abc)(&)(123)
 */
public static String getXMLText(Node node, int i, boolean trim) {
    StringBuffer strBuff = null;

    String text = node.getText(i);
    if (text == null)
        return null;

    for (i++; i < node.getChildCount() && node.getType(i) == Node.TEXT; i++) {
        if (strBuff == null)
            strBuff = new StringBuffer(text);

        strBuff.append(node.getText(i));
    }
    if (strBuff != null)
        text = strBuff.toString();

    if (trim)
        text = text.trim();

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

示例4: getLabel

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

示例5: getLabel

private String getLabel(Element e) {
    if (e.getChildCount() == 0) return null;

    recurseForOutput(e);

    StringBuffer sb = new StringBuffer();
    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));
        }
    }

    return sb.toString().trim();
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:27,代码来源:XFormParser.java

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

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


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