當前位置: 首頁>>代碼示例>>Java>>正文


Java Element.remove方法代碼示例

本文整理匯總了Java中org.dom4j.Element.remove方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.remove方法的具體用法?Java Element.remove怎麽用?Java Element.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.dom4j.Element的用法示例。


在下文中一共展示了Element.remove方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: remove

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  removes a node from the dom4j Document.
 *
 * @param  xpath  Description of the Parameter
 */
public void remove(String xpath) {
	Node node = doc.selectSingleNode(xpath);
	if (node == null) {
		// prtln("remove could not find node to delete (" + xpath + ")");
		return;
	}

	Element parent = node.getParent();
	if (parent == null) {
		// prtln("remove could not find parent of node to delete (" + xpath + ")");
		return;
	}
	if (!parent.remove(node)) {
		prtlnErr("failed to remove node at " + xpath);
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:22,代碼來源:DocMap.java

示例2: removeHttpConfig

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 * 刪除配置
 *
 * @param name
 * @throws Exception
 */
public static void removeHttpConfig(String name) throws Exception {
    SAXReader reader = new SAXReader();
    File xml = new File(HTTP_CONFIG_FILE);
    Document doc;
    Element root;
    try (FileInputStream in = new FileInputStream(xml); Reader read = new InputStreamReader(in, "UTF-8")) {
        doc = reader.read(read);
        root = doc.getRootElement();
        Element cfg = (Element) root.selectSingleNode("/root/configs");
        Element e = (Element) root.selectSingleNode("/root/configs/config[@name='" + name + "']");
        if (e != null) {
            cfg.remove(e);
            CONFIG_MAP.remove(name);
        }
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter writer = new XMLWriter(new FileOutputStream(xml), format);
        writer.write(doc);
        writer.close();
    }
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:28,代碼來源:FileUtil.java

示例3: removeOAISetSpecDefinition

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  Removes the given OAI set definition from the ListSets config XML file and writes it to disc.
 *
 * @param  setsConfigFile  The ListSets config file
 * @param  setSpec         The set to remove
 * @return                 True if the set existed and was removed
 * @exception  Exception   If error
 */
public static boolean removeOAISetSpecDefinition(File setsConfigFile, String setSpec) throws Exception {
	Document document = null;
	if (setsConfigFile == null || !setsConfigFile.exists())
		return false;

	// Create the XML DOM
	if (setsConfigFile.exists()) {
		SAXReader reader = new SAXReader();
		document = reader.read(setsConfigFile);
	}

	Element root = document.getRootElement();
	if (!root.getName().equals("ListSets"))
		throw new Exception("OAI Sets XML is incorrect. Root node is not 'ListSets'");

	// Remove the previous set definition, if present
	String xPath = "set[setSpec=\"" + setSpec + "\"]";
	Element prevSet = (Element) root.selectSingleNode(xPath);
	if (prevSet == null)
		return false;
	root.remove(prevSet);

	// Write the XML to disc
	OutputFormat format = OutputFormat.createPrettyPrint();
	XMLWriter writer = new XMLWriter(new FileWriter(setsConfigFile), format);
	writer.write(document);
	writer.close();

	return true;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:39,代碼來源:OAISetsXMLConfigManager.java

示例4: filterChildren

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  NOT YET DOCUMENTED
 *
 * @param  qualifiedElementName  NOT YET DOCUMENTED
 * @param  parent                NOT YET DOCUMENTED
 */
public void filterChildren(String qualifiedElementName, Element parent) {
	List children = parent.elements();
	for (int i = children.size() - 1; i > -1; i--) {
		Element child = (Element) children.get(i);
		if (child.getQualifiedName().equals(qualifiedElementName))
			parent.remove(child);
		else
			filterChildren(qualifiedElementName, child);
	}
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:17,代碼來源:GenericType.java

示例5: flush

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  Write this User to disk and reset data structures so they will be
 *  reloaded from disk.
 *
 *@exception  Exception  Description of the Exception
 */
public void flush() throws Exception {
	prtln("\n flushing " + this.getUsername());
	// we have to update the prefs and roles structures!

	// UPDATE the document so it will be correctly written
	Element root = (Element) getNode("/record");
	String roles_path = ("/record/roles");
	String prefs_path = ("/record/preferences");
	// delete "roles" and "preferences", and then add again from their maps

	Element rolesElement = (Element) getNode(roles_path);
	if (rolesElement != null && !root.remove(rolesElement)) {
		prtln("WARNING: Roles not removed");
	}
	Element prefsElement = (Element) getNode(prefs_path);
	if (prefsElement != null && !root.remove(prefsElement)) {
		prtln("WARNING: Prefs not removed");
	}

	// insert new elements
	rolesElement = this.rolesMapToElement();
	prefsElement = this.prefMapToElement();

	// add elements constructed from the maps
	if (rolesElement != null)
		root.add(rolesElement);
	if (prefsElement != null)
		root.add(prefsElement);	

	this.reader.flush();
	this.roleMap = null;
	this.prefMap = null;

}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:41,代碼來源:User.java

示例6: pruneRepeatingFields

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 *  Removes empty elements of repeating fields.<p>
 *
 *  DISABLED 5/11/04 - the repository will contain non-valid elements, so we
 *  don't worry so much about getting rid of the empty elements (many of which
 *  will be invalid due to the "stringTextType" convention) Removes empty child
 *  elements from each repeating field in the toPrune list. Children are pruned
 *  if they are empty and their occurance attribute allows them to be deleted.
 */
protected void pruneRepeatingFields() {
	prtln ("\nPruneRepeatingFields()");
	List toPruneList = sef.getRepeatingFieldsToPrune();

	// for each repeating field on the toPrune list
	for (Iterator p = toPruneList.iterator(); p.hasNext(); ) {
		String parentPath = (String) p.next();
		prtln ("\t parent: " + parentPath);
		Element parent = (Element) docMap.selectSingleNode(parentPath);
		if (parent == null) {
			prtln("pruneRepeatingFields(): Element not found for " + parentPath);
			continue;
		}
		List children = parent.elements();
		SchemaNode schemaNode = schemaHelper.getSchemaNode(XPathUtils.normalizeXPath(parentPath));
		if (schemaNode == null) {
			prtln("pruneRepeatingFields() couldn't find SchemaNode");
			continue;
		}

		for (int i = children.size() - 1; i > -1; i--) {
			Element child = (Element) children.get(i);
			String childName = child.getName();
			prtln ("\t     childName: " + childName);
			if (!Dom4jUtils.isEmpty(child)) {
				continue;
			}
			if (parent.elements().size() >= schemaNode.getMinOccurs()) {
				String childPath = child.getPath();
				parent.remove(child);
			}
		}
		parent.setText("");
	}
	sef.clearRepeatingFieldsToPrune();
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:46,代碼來源:SchemEditValidator.java

示例7: removeProcess

import org.dom4j.Element; //導入方法依賴的package包/類
private static void removeProcess(Document document) throws IOException, DocumentException {

        Element root = document.getRootElement();// Get the root node
        List<? extends Node> nodes = root.selectNodes("//*[@android:process]");
        for (Node node : nodes) {
            Element element = (Element)node;
            String process = element.attributeValue("process");
            logger.info("[Remove Element]" + element + process);
            element.remove(element.attribute("process"));
        }
    }
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:12,代碼來源:ManifestFileUtils.java

示例8: remove

import org.dom4j.Element; //導入方法依賴的package包/類
@Override
public void remove(Dom4jNode node) {
    final Node wrappedNode = node.getNode();
    final Element parent = wrappedNode.getParent();
    if (parent != null) {
        parent.remove(wrappedNode);
    } else {
        throw new XmlBuilderException("Unable to remove node " + node
                + ". Node either root or in detached state");
    }
}
 
開發者ID:SimY4,項目名稱:xpath-to-xml,代碼行數:12,代碼來源:Dom4jNavigator.java

示例9: remove

import org.dom4j.Element; //導入方法依賴的package包/類
public boolean remove(Element element) {
	return element.remove( element );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:4,代碼來源:ElementWrapper.java

示例10: saveHttpConfig

import org.dom4j.Element; //導入方法依賴的package包/類
/**
 * 保存http請求信息到xml
 *
 * @param hc
 * @return
 * @throws Exception
 */
public static boolean saveHttpConfig(HttpConfig hc) throws Exception {
    SAXReader reader = new SAXReader();
    File xml = new File(HTTP_CONFIG_FILE);
    Document doc = null;
    Element root = null;
    boolean isNew = true;
    if (!xml.exists()) {
        doc = DocumentHelper.createDocument();
        root = DocumentHelper.createElement("root");
        root.addElement("configs");
        doc.add(root);
    }
    if (doc == null) {
        try (FileInputStream in = new FileInputStream(xml); Reader read = new InputStreamReader(in, "UTF-8")) {
            doc = reader.read(read);
            root = doc.getRootElement();
        }
    }
    Element cfg = (Element) root.selectSingleNode("/root/configs");
    Element e = (Element) root.selectSingleNode("/root/configs/config[@name='" + hc.getName() + "']");
    if (e != null) {
        isNew = false;
        cfg.remove(e);
    }
    CONFIG_MAP.put(hc.getName(), hc);

    Element cfg1 = cfg.addElement("config");
    cfg1.addAttribute("name", hc.getName());
    cfg1.addAttribute("encodeType", hc.getEncodeType());
    cfg1.addAttribute("charset", hc.getCharset());
    cfg1.addAttribute("requestType", hc.getRequestType());
    cfg1.addAttribute("sendXML", hc.getSendXML().toString());
    cfg1.addAttribute("packHead", hc.getPackHead().toString());
    cfg1.addAttribute("lowercaseEncode", hc.getLowercaseEncode().toString());

    cfg1.addElement("url").setText(hc.getUrl());
    cfg1.addElement("header").setText(hc.getHeaderStr());
    cfg1.addElement("parameter").setText(hc.getParameterStr());
    cfg1.addElement("encodeField").setText(hc.getEncodeFieldName());
    cfg1.addElement("encodeKey").setText(hc.getEncodeKey());

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    XMLWriter writer = new XMLWriter(new FileOutputStream(xml), format);
    writer.write(doc);
    writer.close();
    return isNew;
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:56,代碼來源:FileUtil.java


注:本文中的org.dom4j.Element.remove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。