本文整理匯總了Java中org.jdom2.Element.removeContent方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.removeContent方法的具體用法?Java Element.removeContent怎麽用?Java Element.removeContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jdom2.Element
的用法示例。
在下文中一共展示了Element.removeContent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processChildren
import org.jdom2.Element; //導入方法依賴的package包/類
private void processChildren(Path file, Element parent) throws InvalidXMLException {
for(int i = 0; i < parent.getContentSize(); i++) {
Content content = parent.getContent(i);
if(!(content instanceof Element)) continue;
Element child = (Element) content;
List<Content> replacement = null;
switch(child.getName()) {
case "include":
replacement = processIncludeElement(file, child);
break;
case "if":
replacement = processConditional(child, false);
break;
case "unless":
replacement = processConditional(child, true);
break;
}
if(replacement != null) {
parent.removeContent(i);
parent.addContent(i, replacement);
i--; // Process replacement content
} else {
processChildren(file, child);
}
}
}
示例2: doGetPost
import org.jdom2.Element; //導入方法依賴的package包/類
@Override
public void doGetPost(MCRServletJob job) throws Exception {
//prepare request
HttpServletRequest req = job.getRequest();
//get doi from URL
String doi = getParameter(req, "id");
//send request to CrossRef API
Document crossRefDocument = xmlFromDOICrossRef(doi);
Element crossRefExport = crossRefDocument.getRootElement().clone();
Element crossRefElement = new Element("crossref-export");
crossRefElement.addContent(crossRefExport);
//send request to Scopus API
Document scopusDocument = xmlFromDOIScopus(doi);
Element scopusExport = scopusDocument.getRootElement().clone();
Element scopusElement = new Element("scopus-export");
scopusElement.addContent(scopusExport);
System.out.println(scopusElement.getName());
// check, if the scopus-export contains multiple results
if(potentialScopusResult(scopusElement)) {
ExportComparator comp = new ExportComparator();
Element fittingElement = comp.getFittingElement(scopusElement, crossRefElement);
Element newScopusElement = fittingElement
.getChild("extension", modsNS).clone();
scopusElement.removeContent();
scopusElement.setContent(newScopusElement);
}
//build document
Document fullDoc = new Document();
Element rootElement = new Element("api-retrieval");
rootElement.addContent(crossRefElement);
rootElement.addContent(scopusElement);
fullDoc.setRootElement(rootElement);
XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
xmlOutput.output(fullDoc, new FileWriter("AllExport_DOI_mods.xml"));
scopusConnection.close();
crossRefConnection.close();
}