Java Code Examples for org.dom4j.Element.nodeCount()

The following are Jave code examples for showing how to use nodeCount() of the org.dom4j.Element class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: testing_platform   File: Tools.java   View Source Code Vote up 6 votes
private static void read(Element e) {
    String result = "";
    if( !"".equals(targetPath) ){
        return ;
    }
    if (e.nodeCount() > 0) {
        Iterator<Element> it = e.elementIterator();
        while (it.hasNext()) {
            Element ele = it.next();
            if( "CSVDataSet".equals(ele.getName()) ){
                /*if("".equals(targetPath)){ //查到的第一个 CSVDataSet 保存到参数中,
                    targetPath = ele.getUniquePath();
                }*/
                targetPath = ele.getUniquePath();
            }
            read(ele);
        }
    }

}
 
Example 2
Project: TestDemo1-github   File: Dom4jHelper.java   View Source Code Vote up 5 votes
/**
 * 遍历解析元素
 * @param element
 */
public void treeWalk(Element element) {
    for ( int i = 0, size = element.nodeCount(); i < size; i++ ) {
        Node node = element.node(i);
        if ( node instanceof Element ) {
            treeWalk( (Element) node );
        }
        else {
            // 处理....
        }
    }
}
 
Example 3
Project: unitimes   File: LowercaseTableNames.java   View Source Code Vote up 4 votes
protected void writeElement(Element element) throws IOException {
    int size = element.nodeCount();
    String qualifiedName = element.getQualifiedName();

    writePrintln();
    indent();

    writer.write("<");
    writer.write(qualifiedName);

    boolean textOnly = true;

    for (int i = 0; i < size; i++) {
        Node node = element.node(i);
        if (node instanceof Element) {
            textOnly = false;
        } else if (node instanceof Comment) {
            textOnly = false;
        }
    }

    writeAttributes(element);

    lastOutputNodeType = Node.ELEMENT_NODE;

    if (size <= 0) {
        writeEmptyElementClose(qualifiedName);
    } else {
        writer.write(">");

        if (textOnly) {
            // we have at least one text node so lets assume
            // that its non-empty
            writeElementContent(element);
        } else {
        	if (element.attributeCount() > 3)
        		writePrintln();
            // we know it's not null or empty from above
            ++indentLevel;

            writeElementContent(element);

            --indentLevel;

            writePrintln();
            indent();
        }

        writer.write("</");
        writer.write(qualifiedName);
        writer.write(">");
    }
   	if (element.attributeCount() > 2 && indentLevel > 0)
   		writePrintln();

    lastOutputNodeType = Node.ELEMENT_NODE;
}