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


Java Element.attributeCount方法代码示例

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


在下文中一共展示了Element.attributeCount方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: element2Map

import org.dom4j.Element; //导入方法依赖的package包/类
/**
 * Element to map
 * @param e
 * @param map
 */
public static void element2Map(Element e, Map<String, Object> map) {
    List<Object> list = e.elements();
    if (e.attributeCount() > 0) {
        for (Object attri : e.attributes()) {
            Attribute at = (Attribute)attri;
            map.put(at.getName(), at.getValue());
        }
    }
    if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
        return;
    } else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
        map.put("text", e.getText());
    }
    for (Object aList : list) {
        Element iter = (Element)aList;
        Map<String, Object> cMap = new HashMap<String, Object>();
        element2Map(iter, cMap);
        map.put(iter.getName(), cMap);
    }
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:26,代码来源:XmlUtil.java

示例2: element2Map

import org.dom4j.Element; //导入方法依赖的package包/类
/**
 * Element to map
 * 
 * @param e
 * @return
 */
public static void element2Map(Element e, Map<String, Object> map) {
	List<Object> list = e.elements();
	if (e.attributeCount() > 0) {
		for (Object attri : e.attributes()) {
			Attribute at = (Attribute) attri;
			map.put(at.getName(), at.getValue());
		}
	}
	if (list.size() < 1 && DataUtil.isEmpty(e.getText())) {
		return;
	} else if (list.size() < 1 && !DataUtil.isEmpty(e.getText())) {
		map.put("text", e.getText());
	}
	for (Object aList : list) {
		Element iter = (Element) aList;
		Map<String, Object> cMap = new HashMap<String, Object>();
		element2Map(iter, cMap);
		map.put(iter.getName(), cMap);
	}
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:27,代码来源:XmlUtil.java

示例3: writeAttributes

import org.dom4j.Element; //导入方法依赖的package包/类
protected void writeAttributes(Element element) throws IOException {
    for (int i = 0, size = element.attributeCount(); i < size; i++) {
        Attribute attribute = element.attribute(i);
           char quote = format.getAttributeQuoteCharacter();
           if (element.attributeCount() > 2) {
               writePrintln();
               indent();
               writer.write(format.getIndent());
           } else {
           	writer.write(" ");
           }
           writer.write(attribute.getQualifiedName());
           writer.write("=");
           writer.write(quote);
           writeEscapeAttributeEntities(attribute.getValue());
           writer.write(quote);
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:19,代码来源:LowercaseTableNames.java

示例4: hasChildren

import org.dom4j.Element; //导入方法依赖的package包/类
/**
 *  Return true if the specified node is an Element and has either a
 *  sub-element, or an attribute (even if they are empty), OR content.
 *
 * @param  xpath  xpath to the node to be evaluated for children
 * @return        true if sub-elements, or attributes, false otherwise or if
 *      node is not an Element
 */
public boolean hasChildren(String xpath) {
	// prtln ("\nhasChildren: " + xpath);
	if (xpath == null || xpath.trim().length() == 0)
		return false;
	Node node = doc.selectSingleNode(xpath);
	if (node == null) {
		prtlnErr("\thasChildren() could not find node: (" + xpath + ")");
		return false;
	}

	if (node.getNodeType() != Node.ELEMENT_NODE) {
		prtlnErr("hasChildern() called with an non-Element - returning false");
		return false;
	}

	Element e = (Element) node;

	// we used to check for "hasText" but why would we want to do that here???
	/*
		We DO want to check in the case of an element that can contain text which ALSO
		has attributes. So we can do this check IF the typeDef is the right kind ...
	*/
	boolean hasText = (e.getTextTrim() != null && e.getTextTrim().length() > 0);
	if (hasText)
		return true;

	return (e.elements().size() > 0 ||
		e.attributeCount() > 0);
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:38,代码来源:DocMap.java

示例5: writeElement

import org.dom4j.Element; //导入方法依赖的package包/类
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;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:58,代码来源:LowercaseTableNames.java


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