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


Java Element.getChild方法代码示例

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


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

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

示例3: readResponseDocument

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
/**
 *
 * @param response
 * @return
 */
private User readResponseDocument(Document response) throws UnrecognizedResponseException {

    if("OpenRosaResponse".equals(response.getRootElement().getName()) && XMLNS_ORR.equals(response.getRootElement().getNamespace())) {
        return readResponseDocumentNew(response);
    }

    //do we want to look for some kind of 'ok' message? otherwise the server could send back
    //gibberish and we'd still interpret it as a successful registration. ideally, we should
    //require a certain 'ok' token, and throw the exception if it's not present

    boolean updates = false;
    for(int i = 0; i < response.getChildCount(); ++i) {
        Object o = response.getChild(i);
        if(!(o instanceof Element)) {
            continue;
        }
        Element e = (Element)o;
        if(e.getName().equals("response-message")) {
            //Do we want to actually just print out the message? That seems weird
            //given the internationalization
        } else if(e.getName().equals("user-data")){
            for(int j = 0; j < response.getChildCount(); ++j) {
                Object data = e.getChild(j);
                if(!(data instanceof Element)) {
                    continue;
                }
                Element dataElement = (Element)data;
                String propertyName = dataElement.getAttributeValue(null, "key");
                String property = (String)dataElement.getChild(0);
                user.setProperty(propertyName, property);
                updates = true;
            }
        }
    }
    return user;
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:42,代码来源:HttpUserRegistrationTranslator.java

示例4: getLabel

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
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,代码行数:28,代码来源:XFormParser.java

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

示例6: isDOMEqualRecursive

import org.kxml2.kdom.Element; //导入方法依赖的package包/类
public static void isDOMEqualRecursive(Element left, Element right) throws RuntimeException {
    if(!left.getName().equals(right.getName())) {
        throw new RuntimeException(String.format("Mismatched element names '%s' and '%s'", left.getName(), right.getName()));
    }

    if(left.getAttributeCount() != right.getAttributeCount()) {
        throw new RuntimeException(String.format("Mismatched attributes for node '%s' ", left.getName()));
    }

    Hashtable<String, String> leftAttr = attrTable(left);
    Hashtable<String, String> rightAttr = attrTable(right);

    for (String key : leftAttr.keySet()) {
        if (!rightAttr.containsKey(key)) {
            throw new RuntimeException(String.format("Mismatched attributes for node '%s' ", left.getName()));
        }

        if (!leftAttr.get(key).equals(rightAttr.get(key))) {
            throw new RuntimeException(String.format("Mismatched attributes for node '%s' ", left.getName()));
        }
    }

    if (left.getChildCount() != right.getChildCount()) {
        throw new RuntimeException(String.format("Mismatched child count (%d,%d) for node '%s' ", left.getChildCount(), right.getChildCount(), left.getName()));
    }

    for (int i = 0; i < left.getChildCount(); ++i) {
        Object l = left.getChild(i);
        Object r = right.getChild(i);

        if (left.getType(i) != right.getType(i)) {
            throw new RuntimeException(String.format("Mismatched children for node '%s' ", left.getName()));
        }

        if(l instanceof Element) {
            isDOMEqualRecursive((Element)l, (Element)r);
        } else if(l instanceof String) {
            if(!l.equals(r)) {
                throw new RuntimeException(String.format("Mismatched element values '%s' and '%s'", l, r));
            }
        }
    }
}
 
开发者ID:dimagi,项目名称:commcare-j2me,代码行数:44,代码来源:XmlComparator.java


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