本文整理汇总了Java中org.dom4j.Element.selectSingleNode方法的典型用法代码示例。如果您正苦于以下问题:Java Element.selectSingleNode方法的具体用法?Java Element.selectSingleNode怎么用?Java Element.selectSingleNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.Element
的用法示例。
在下文中一共展示了Element.selectSingleNode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: RemoteResultDoc
import org.dom4j.Element; //导入方法依赖的package包/类
/**
* Construct a RemoteResultDoc from a MatchingRecord element (of the reponse
* from the UrlCheck Web Service)
*
*@param record matching record {@link org.dom4j.Element}
*@param rs instance of {@link RemoteSearcher}
*/
public RemoteResultDoc(Element record, RemoteSearcher rs) {
// prtln ("constructor with element:\n\t " + e.asXML());
this.rs = rs;
url = record.element("url").getText();
Element head = record.element("head");
try {
Element collectionElement = (Element) head.selectSingleNode("collection");
collection = collectionElement.getText();
id = head.selectSingleNode("id").getText();
} catch (Throwable te) {
prtln("RemoteResultDoc unable to parse element: " + te.getMessage());
}
}
示例4: getSimpleContentType
import org.dom4j.Element; //导入方法依赖的package包/类
/**
* Gets the base extension type of the simpleContent element of the
* ComplexType.
*
* @return The base extension type name if this ComplexType has
* simpleContent, null otherwise.
*/
public String getSimpleContentType() {
if (!hasSimpleContent()) {
return null;
}
Element e = getElement();
Node node = e.selectSingleNode(NamespaceRegistry.makeQualifiedName(xsdPrefix, "simpleContent") + "/" +
NamespaceRegistry.makeQualifiedName(xsdPrefix, "extension"));
if (node == null) {
prtln("extension node not found for " + getName());
return null;
}
return ((Element) node).attributeValue("base");
}
示例5: 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;
}