本文整理了Java中org.w3c.dom.Element.getParentNode()
方法的一些代码示例,展示了Element.getParentNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getParentNode()
方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:getParentNode
暂无
代码示例来源:origin: osmandapp/Osmand
public static void collectPatterns(Document document) {
NodeList nl = document.getElementsByTagName("pattern");
while(nl.getLength() > 0) {
Element pt = (Element) nl.item(0);
String id = pt.getAttribute("id");
patterns.put(id, pt);
pt.getParentNode().removeChild(pt);
}
}
代码示例来源:origin: looly/hutool
/**
* 根据节点名获得第一个子节点
*
* @param element 节点
* @param tagName 节点名
* @return 节点
*/
public static Element getElement(Element element, String tagName) {
final NodeList nodeList = element.getElementsByTagName(tagName);
if (nodeList == null || nodeList.getLength() < 1) {
return null;
}
int length = nodeList.getLength();
for (int i = 0; i < length; i++) {
Element childEle = (Element) nodeList.item(i);
if (childEle == null || childEle.getParentNode() == element) {
return childEle;
}
}
return null;
}
代码示例来源:origin: ehcache/ehcache3
@Override
public ServiceConfiguration<XAStore.Provider> parseServiceConfiguration(Element fragment, ClassLoader classLoader) {
String localName = fragment.getLocalName();
if ("xa-store".equals(localName)) {
String uniqueXAResourceId = fragment.getAttribute("unique-XAResource-id");
return new XAStoreConfiguration(uniqueXAResourceId);
} else {
throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
}
}
代码示例来源:origin: plutext/docx4j
Node n1 = el.getParentNode();
if (n1 == null || Node.ELEMENT_NODE != n1.getNodeType()) {
return;
while (parent != null && Node.ELEMENT_NODE == parent.getNodeType()) {
parents.add((Element)parent);
parent = parent.getParentNode();
代码示例来源:origin: stackoverflow.com
int nodeValue = Integer.parseInt(nodeNumber);
NodeList bookList = doc.getElementsByTagName("book");
Node nNode = bookList.item(nodeValue);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
eElement.getParentNode().removeChild(nNode);
}
代码示例来源:origin: org.jasig.portal/uPortal-layout-impl
@Override
public String getParentId(String nodeId) throws PortalException {
String parentId = null;
Element element = layout.getElementById(nodeId);
if (element != null) {
Node parent = element.getParentNode();
if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
Element parentE = (Element) parent;
parentId = parentE.getAttribute("ID");
}
}
return parentId;
}
代码示例来源:origin: com.android.tools.lint/lint-checks
private static boolean parentDefinesSelectableItem(Element element) {
String background = element.getAttributeNS(ANDROID_URI, ATTR_BACKGROUND);
if (VALUE_SELECTABLE_ITEM_BACKGROUND.equals(background)) {
return true;
}
Node parent = element.getParentNode();
if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
return parentDefinesSelectableItem((Element) parent);
}
return false;
}
代码示例来源:origin: osmandapp/Osmand
protected static void copyAndReplaceElement(Element oldElement, Element newElement) {
while(oldElement.getChildNodes().getLength() > 0) {
newElement.appendChild(oldElement.getChildNodes().item(0));
}
NamedNodeMap attrs = oldElement.getAttributes();
for(int i = 0; i < attrs.getLength(); i++) {
Node ns = attrs.item(i);
newElement.setAttribute(ns.getNodeName(), ns.getNodeValue());
}
((Element)oldElement.getParentNode()).replaceChild(newElement, oldElement);
}
}
代码示例来源:origin: looly/hutool
/**
* 根据节点名获得第一个子节点
*
* @param element 节点
* @param tagName 节点名
* @return 节点
*/
public static Element getElement(Element element, String tagName) {
final NodeList nodeList = element.getElementsByTagName(tagName);
if (nodeList == null || nodeList.getLength() < 1) {
return null;
}
int length = nodeList.getLength();
for (int i = 0; i < length; i++) {
Element childEle = (Element) nodeList.item(i);
if (childEle == null || childEle.getParentNode() == element) {
return childEle;
}
}
return null;
}
代码示例来源:origin: ehcache/ehcache3
@Override
public ServiceConfiguration<ClusteredStore.Provider> parseServiceConfiguration(Element fragment, ClassLoader classLoader) {
if (CLUSTERED_STORE_ELEMENT_NAME.equals(fragment.getLocalName())) {
if (fragment.hasAttribute(CONSISTENCY_ATTRIBUTE_NAME)) {
return new ClusteredStoreConfiguration(Consistency.valueOf(fragment.getAttribute("consistency").toUpperCase()));
} else {
return new ClusteredStoreConfiguration();
}
}
throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
}
代码示例来源:origin: wsdl4j/wsdl4j
short nodeType = context.getNodeType ();
Node tempNode = null;
while (tempNode != null && tempNode.getNodeType () == Node.ELEMENT_NODE)
tempNode = tempEl.getParentNode ();
代码示例来源:origin: com.amazon.device.tools.lint/lint-checks
private static boolean parentDefinesSelectableItem(Element element) {
String background = element.getAttributeNS(ANDROID_URI, ATTR_BACKGROUND);
if (VALUE_SELECTABLE_ITEM_BACKGROUND.equals(background)) {
return true;
}
Node parent = element.getParentNode();
if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
return parentDefinesSelectableItem((Element) parent);
}
return false;
}
代码示例来源:origin: osmandapp/Osmand
public static void combineAllApplyTags(Document document) {
NodeList nl = document.getElementsByTagName("apply");
while(nl.getLength() > 0) {
Element app = (Element) nl.item(0);
Element parent = (Element) app.getParentNode();
NamedNodeMap attrs = app.getAttributes();
for(int i = 0; i < attrs.getLength(); i++) {
Node ns = attrs.item(i);
parent.setAttribute(ns.getNodeName(), ns.getNodeValue());
}
while(app.getChildNodes().getLength() > 0) {
Node ni = app.getChildNodes().item(0);
app.getParentNode().insertBefore(ni, app);
}
app.getParentNode().removeChild(app);
}
}
代码示例来源:origin: marytts/marytts
public static void replaceElement(Element oldElement, NodeList newNodes) {
Document doc = oldElement.getOwnerDocument();
Node parent = oldElement.getParentNode();
int len = newNodes.getLength();
for (int i = 0; i < len; i++) {
Node n = newNodes.item(i);
if (!doc.equals(n.getOwnerDocument())) {
// first we need to import the node into the document
n = doc.importNode(n, true);
}
parent.insertBefore(n, oldElement);
}
parent.removeChild(oldElement);
}
代码示例来源:origin: ehcache/ehcache3
@Override
public ServiceConfiguration<Jsr107Service> parseServiceConfiguration(Element fragment, ClassLoader classLoader) {
String localName = fragment.getLocalName();
if ("mbeans".equals(localName)) {
ConfigurationElementState managementEnabled = ConfigurationElementState.UNSPECIFIED;
ConfigurationElementState statisticsEnabled = ConfigurationElementState.UNSPECIFIED;
if (fragment.hasAttribute(MANAGEMENT_ENABLED_ATTRIBUTE)) {
managementEnabled = Boolean.parseBoolean(fragment.getAttribute(MANAGEMENT_ENABLED_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
}
if (fragment.hasAttribute(STATISTICS_ENABLED_ATTRIBUTE)) {
statisticsEnabled = Boolean.parseBoolean(fragment.getAttribute(STATISTICS_ENABLED_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
}
return new Jsr107CacheConfiguration(statisticsEnabled, managementEnabled);
} else {
throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
}
}
代码示例来源:origin: danfickle/openhtmltopdf
public Object getParentElement(Object element) {
Node parent = ((org.w3c.dom.Element) element).getParentNode();
if (parent.getNodeType() != Node.ELEMENT_NODE) parent = null;
return parent;
}
代码示例来源:origin: looly/hutool
/**
* 将NodeList转换为Element列表<br>
* 非Element节点将被忽略
*
* @param parentEle 父节点,如果指定将返回此节点的所有直接子节点,nul返回所有就节点
* @param nodeList NodeList
* @return Element列表
*/
public static List<Element> transElements(Element parentEle, NodeList nodeList) {
int length = nodeList.getLength();
final ArrayList<Element> elements = new ArrayList<Element>(length);
Node node;
Element element;
for (int i = 0; i < length; i++) {
node = nodeList.item(i);
if (Node.ELEMENT_NODE == node.getNodeType()) {
element = (Element) nodeList.item(i);
if (parentEle == null || element.getParentNode() == parentEle) {
elements.add(element);
}
}
}
return elements;
}
代码示例来源:origin: marytts/marytts
public static void replaceElement(Element oldElement, NodeList newNodes) {
Document doc = oldElement.getOwnerDocument();
Node parent = oldElement.getParentNode();
int len = newNodes.getLength();
for (int i = 0; i < len; i++) {
Node n = newNodes.item(i);
if (!doc.equals(n.getOwnerDocument())) {
// first we need to import the node into the document
n = doc.importNode(n, true);
}
parent.insertBefore(n, oldElement);
}
parent.removeChild(oldElement);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
String sizeString = tmpEl.getAttribute("size");
+ ", data contains " + sall.size());
currentElem = (Element) tmpEl.getParentNode();
return sall.toArray(new ArrayList[0][]);
} catch (IOException ioe) {
代码示例来源:origin: com.google.code.maven-play-plugin.org.xhtmlrenderer/core-renderer
public Object getParentElement(Object element) {
Node parent = ((org.w3c.dom.Element) element).getParentNode();
if (parent.getNodeType() != Node.ELEMENT_NODE) parent = null;
return parent;
}
内容来源于网络,如有侵权,请联系作者删除!