本文整理了Java中org.w3c.dom.Element.removeChild()
方法的一些代码示例,展示了Element.removeChild()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.removeChild()
方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:removeChild
暂无
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Common routine to remove all children nodes from the passed element container
* @param parentElement
* @param nodeName
* @throws XPathExpressionException
*/
protected void clearNode(Element parentElement, String nodeName) throws XPathExpressionException {
if (parentElement.hasChildNodes()) {
NodeList children = (NodeList) xPath.evaluate(nodeName, parentElement, XPathConstants.NODESET);
for (int j = 0; j < children.getLength(); j++) {
parentElement.removeChild(children.item(j));
}
children = parentElement.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
if (children.item(j).getNodeName().equalsIgnoreCase("#text")) {
parentElement.removeChild(children.item(j));
}
}
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
element.removeChild(txtNode);
if (element.getFirstChild() != null)
element.insertBefore(txtNode, element.getFirstChild());
代码示例来源:origin: org.eclipse/org.eclipse.jst.server.tomcat.core
/**
* Removes the mime mapping at the specified index.
*
* @param index int
*/
public void removeMimeMapping(int index) {
Element element = webAppDocument.getDocumentElement();
NodeList list = element.getElementsByTagName("mime-mapping");
Node node = list.item(index);
element.removeChild(node);
isWebAppDirty = true;
}
代码示例来源:origin: org.pustefixframework/pustefix-core
private static void swallowStartElement(Element root) {
NamedNodeMap attrMap = root.getAttributes();
NodeList childNodes = root.getChildNodes();
if(attrMap.getLength() == 0 && childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == Node.ELEMENT_NODE) {
Element child = (Element)childNodes.item(0);
if(child.getNodeName().equals(root.getNodeName())) {
NamedNodeMap attrs = child.getAttributes();
for(int i=0; i<attrs.getLength(); i++) {
Attr attrNode = (Attr)attrs.item(i);
root.setAttributeNode(((Attr)attrNode.cloneNode(true)));
}
while(child.hasChildNodes()) {
root.appendChild(child.removeChild(child.getFirstChild()));
}
root.removeChild(child);
}
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-xml
/**
* Moves all child elements of the parent into destination element.
*
* @param parent the parent {@link Element}.
* @param destination the destination {@link Element}.
*/
protected void moveChildren(Element parent, Element destination)
{
NodeList children = parent.getChildNodes();
while (children.getLength() > 0) {
destination.appendChild(parent.removeChild(parent.getFirstChild()));
}
}
}
代码示例来源:origin: marytts/marytts
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child instanceof Element) {
trimEmptyTextNodes(child);
element.removeChild(n);
代码示例来源:origin: stackoverflow.com
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc = factory.newDocumentBuilder().parse("booking-request.xml");
Element bookingRequest = doc.getDocumentElement();
Element contract = (Element)bookingRequest.getElementsByTagName("Contract").item(0);
Element trades = (Element)contract.getElementsByTagName("Trades").item(0);
List<Element> tradeList = new ArrayList<Element>();
NodeList nodeList = trades.getElementsByTagName("Trade");
for(int i=0; i<nodeList.getLength(); i++)
tradeList.add((Element)nodeList.item(i));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
int i = 0;
for(Element trade: tradeList){
// remove all children of <Trades>
while(trades.getFirstChild()!=null)
trades.removeChild(trades.getFirstChild());
trades.appendChild(doc.createTextNode("\n "));
trades.appendChild(trade);
trades.appendChild(doc.createTextNode("\n "));
++i;
transformer.transform(new DOMSource(doc), new StreamResult(new File("trade"+i+".xml")));
}
代码示例来源:origin: org.opendaylight.netconf/netconf-util
private static void removeEventTimeNode(Document document) {
final Node eventTimeNode = document.getDocumentElement().getElementsByTagNameNS(
XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME).item(0);
document.getDocumentElement().removeChild(eventTimeNode);
}
代码示例来源:origin: org.xwiki.commons/xwiki-commons-xml
/**
* Moves all child elements of the parent into destination element.
*
* @param parent the parent {@link Element}.
* @param destination the destination {@link Element}.
*/
protected void moveChildren(Element parent, Element destination)
{
NodeList children = parent.getChildNodes();
while (children.getLength() > 0) {
destination.appendChild(parent.removeChild(parent.getFirstChild()));
}
}
}
代码示例来源:origin: net.oneandone/sushi
public static void clear(Element root) {
Node child;
while (true) {
child = root.getFirstChild();
if (child == null) {
break;
}
root.removeChild(child);
}
}
代码示例来源:origin: marytts/marytts
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child instanceof Element) {
trimEmptyTextNodes(child);
element.removeChild(n);
代码示例来源:origin: dita-ot/dita-ot
private Map<File, Map<String, Element>> getMapping(Document doc) {
final Map<File, Map<String, Element>> map = new HashMap<>();
final NodeList maplinks = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < maplinks.getLength(); i++) {
final Node n = maplinks.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
final Element maplink = (Element) n;
final URI href = toURI(maplink.getAttribute(ATTRIBUTE_NAME_HREF));
final File path = toFile(stripFragment(href));
String fragment = href.getFragment();
if (fragment == null) {
fragment = SHARP;
}
Map<String, Element> m = map.computeIfAbsent(path, k -> new HashMap<>());
Element stub = m.computeIfAbsent(fragment, k -> doc.createElement("stub"));
Node c = maplink.getFirstChild();
while (c != null) {
final Node nextSibling = c.getNextSibling();
stub.appendChild(maplink.removeChild(c));
c = nextSibling;
}
}
}
return map;
}
代码示例来源:origin: SAMLRaider/SAMLRaider
public void applyXSW6(Document document){
Element evilAssertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0);
Element originalSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0);
Element assertion = (Element) evilAssertion.cloneNode(true);
Element copiedSignature = (Element) assertion.getElementsByTagNameNS("*", "Signature").item(0);
assertion.removeChild(copiedSignature);
originalSignature.appendChild(assertion);
evilAssertion.setAttribute("ID", "_evil_assertion_ID");
}
代码示例来源:origin: danfickle/openhtmltopdf
void convert(Element latexElement) throws IOException {
String rawInputLaTeX = latexElement.getTextContent();
String inputLaTeX = rawInputLaTeX.replaceAll("(\r\n|\r|\n)", "\n");
SnuggleEngine engine = createSnuggleEngine();
SnuggleSession session = engine.createSession();
SnuggleInput input = new SnuggleInput(inputLaTeX, "LaTeX Element");
try {
session.parseInput(input);
} catch (Exception e) {
throw new IOException("Error while parsing: " + rawInputLaTeX + ": " + e.getMessage(), e);
}
while (latexElement.getChildNodes().getLength() != 0)
latexElement.removeChild(latexElement.getFirstChild());
DOMOutputOptions options = new DOMOutputOptions();
options.setErrorOutputOptions(DOMOutputOptions.ErrorOutputOptions.XHTML);
try {
session.buildDOMSubtree(latexElement, options);
} catch (Exception e) {
throw new IOException("Error while building DOM for: " + rawInputLaTeX + ": " + e.getMessage(), e);
}
}
代码示例来源:origin: net.wetheinter/gwt-user
private static void clearChildren(Element elem) {
// TODO(rjrjr) I'm nearly positive that anywhere this is called
// we should instead be calling assertNoBody
Node child;
while ((child = elem.getFirstChild()) != null) {
elem.removeChild(child);
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
for (int i = 0; i < oldComments.getLength(); i++) {
Node node = oldComments.item(i);
if (node.getNodeType() == Node.COMMENT_NODE && node.getNodeValue().equals(name)) {
addComment = false;
org.w3c.dom.Element former = find(file, entry.getKey(), "attr");
if (former != null) {
file.removeChild(former);
} else if (contents != null) {
NodeList oldContents = file.getChildNodes();
for (int i = 0; i < oldContents.getLength();) {
Node node = oldContents.item(i);
if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
file.removeChild(node);
} else {
i++;
代码示例来源:origin: SAMLRaider/SAMLRaider
public void applyXSW3(Document document){
Element assertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0);
Element evilAssertion = (Element) assertion.cloneNode(true);
Element copiedSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0);
evilAssertion.setAttribute("ID", "_evil_assertion_ID");
evilAssertion.removeChild(copiedSignature);
document.getDocumentElement().insertBefore(evilAssertion, assertion);
}
代码示例来源:origin: org.jooq/joox-java-6
private final void empty(Element element) {
Node child;
while ((child = element.getFirstChild()) != null)
element.removeChild(child);
}
代码示例来源:origin: org.netbeans.api/org-openide-util
for (int i = 0; i < nl.getLength(); i++) {
if (nl.item(i) instanceof DocumentType) {
doctype = (DocumentType) nl.item(i);
doc = builder.newDocument();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (!(node instanceof DocumentType)) {
try {
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.item(i);
removeXmlBase(e);
Node n = nl2.item(j);
if (n instanceof Text && ((Text) n).getNodeValue().trim().length() == 0) {
e.removeChild(n);
代码示例来源:origin: SAMLRaider/SAMLRaider
public void applyXSW8(Document document){
Element evilAssertion = (Element) document.getElementsByTagNameNS("*", "Assertion").item(0);
Element originalSignature = (Element) evilAssertion.getElementsByTagNameNS("*", "Signature").item(0);
Element assertion = (Element) evilAssertion.cloneNode(true);
Element copiedSignature = (Element) assertion.getElementsByTagNameNS("*", "Signature").item(0);
assertion.removeChild(copiedSignature);
Element object = document.createElement("Object");
originalSignature.appendChild(object);
object.appendChild(assertion);
}
内容来源于网络,如有侵权,请联系作者删除!