本文整理汇总了Java中org.w3c.dom.Element.getParentNode方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getParentNode方法的具体用法?Java Element.getParentNode怎么用?Java Element.getParentNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Element
的用法示例。
在下文中一共展示了Element.getParentNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
super.startElement(namespaceURI, localName, qName, atts);
Element e = getCurrentElement();
locatorTable.storeStartLocation( e, locator );
// check if this element is an outer-most <jaxb:bindings>
if( Const.JAXB_NSURI.equals(e.getNamespaceURI())
&& "bindings".equals(e.getLocalName()) ) {
// if this is the root node (meaning that this file is an
// external binding file) or if the parent is XML Schema element
// (meaning that this is an "inlined" external binding)
Node p = e.getParentNode();
if( p instanceof Document
||( p instanceof Element && !e.getNamespaceURI().equals(p.getNamespaceURI()))) {
outerMostBindings.add(e); // remember this value
}
}
}
示例2: traverseLevel
import org.w3c.dom.Element; //导入方法依赖的package包/类
private static void traverseLevel(TreeWalker walker, Element topParent, String indent) {
// describe current node:
Element current = (Element) walker.getCurrentNode();
//System.out.println(indent + "- " + ((Element) current).getTagName());
// store elements which need to be moved
if (topParent != null) {
Element parent = (Element) current.getParentNode();
if (parent != null && !topParent.equals(parent)) {
OutputFilter outputFilter = (OutputFilter)walker.getFilter();
outputFilter.getToAddList(topParent).add(current);
}
}
// traverse children:
for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
traverseLevel(walker, current, indent + '\t');
}
// return position to the current (level up):
walker.setCurrentNode(current);
}
示例3: getAttributeWithInheritance
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Returns an attribute value from this node, or first parent node with this attribute defined
*
* @return A non-zero-length value if defined, otherwise null
*/
public static String getAttributeWithInheritance(Element element, String attributeName) {
String result = element.getAttribute(attributeName);
if ((result == null) || ("".equals(result))) {
Node n = element.getParentNode();
if ((n == element) || (n == null)) {
return null;
}
if (n instanceof Element) {
Element parent = (Element) n;
return getAttributeWithInheritance(parent, attributeName);
}
return null; //we reached the top level of the document without finding attribute
}
return result;
}
示例4: startElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
super.startElement(namespaceURI, localName, qName, atts);
Element e = getCurrentElement();
locatorTable.storeStartLocation( e, locator );
// check if this element is an outer-most <jaxb:bindings>
if( JAXWSBindingsConstants.JAXWS_BINDINGS.getNamespaceURI().equals(e.getNamespaceURI())
&& "bindings".equals(e.getLocalName()) ) {
// if this is the root node (meaning that this file is an
// external binding file) or if the parent is XML Schema element
// (meaning that this is an "inlined" external binding)
Node p = e.getParentNode();
if( p instanceof Document) {
outerMostBindings.add(e); // remember this value
}
}
}
示例5: getIdentifier
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Returns a previously registered element with the specified
* identifier name, or null if no element is registered.
*
* @see #putIdentifier
* @see #removeIdentifier
*/
public Element getIdentifier(String idName) {
if (needsSyncData()) {
synchronizeData();
}
if (identifiers == null) {
return null;
}
Element elem = (Element) identifiers.get(idName);
if (elem != null) {
// check that the element is in the tree
Node parent = elem.getParentNode();
while (parent != null) {
if (parent == this) {
return elem;
}
parent = parent.getParentNode();
}
}
return null;
}
示例6: test
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public boolean test(Element start, Element root) {
if (start == root) {
return false;
}
Node parent = start.getParentNode();
if (parent == root) {
return false;
}
Element element = (Element)parent;
return test(element) && testPrevious(element, root);
}
示例7: filterProjectXML
import org.w3c.dom.Element; //导入方法依赖的package包/类
private static void filterProjectXML(FileObject fo, ZipInputStream str, String name) throws IOException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileUtil.copy(str, baos);
Document doc = XMLUtil.parse(new InputSource(new ByteArrayInputStream(baos.toByteArray())), false, false, null, null);
NodeList nl = doc.getDocumentElement().getElementsByTagName("name");
if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Element el = (Element) nl.item(i);
if (el.getParentNode() != null && "data".equals(el.getParentNode().getNodeName())) {
NodeList nl2 = el.getChildNodes();
if (nl2.getLength() > 0) {
nl2.item(0).setNodeValue(name);
}
break;
}
}
}
OutputStream out = fo.getOutputStream();
try {
XMLUtil.write(doc, out, "UTF-8");
} finally {
out.close();
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
writeFile(str, fo);
}
}
示例8: removeNodeSpi
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Removes this node from the backing store. Please note that, though the
* AbstractPreferences method signature defines that this method should
* throw a BackingStoreException, this implementation doesn't.
*/
protected void removeNodeSpi() throws BackingStoreException {
org.w3c.dom.Node root = AIPreferencesController.getInstance().getXMLDocument().getDocumentElement();
Element myNode = myXMLNode();
Element parentNode = (Element)myNode.getParentNode();
if(root.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
Element docRoot = (Element) root;
parentNode.removeChild(myNode);
}
}
示例9: test
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public boolean test(Element start, Element root) {
if (start == root) {
return false;
}
Node parent = start.getParentNode();
while (parent != root) {
Element element = (Element)parent;
if (test(element) && testPrevious(element, root)) {
return true;
}
parent = parent.getParentNode();
}
return false;
}
示例10: filterProjectXML
import org.w3c.dom.Element; //导入方法依赖的package包/类
private static void filterProjectXML(FileObject fo, ZipInputStream str, String name) throws IOException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileUtil.copy(str, baos);
Document doc = XMLUtil.parse(new InputSource(new ByteArrayInputStream(baos.toByteArray())), false, false, null, null);
NodeList nl = doc.getDocumentElement().getElementsByTagName("name");
if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Element el = (Element) nl.item(i);
if (el.getParentNode() != null && "data".equals(el.getParentNode().getNodeName())) {
NodeList nl2 = el.getChildNodes();
if (nl2.getLength() > 0) {
nl2.item(0).setNodeValue(name);
}
break;
}
}
}
try (OutputStream out = fo.getOutputStream()) {
XMLUtil.write(doc, out, "UTF-8");
}
} catch (IOException | DOMException | SAXException ex) {
Exceptions.printStackTrace(ex);
writeFile(str, fo);
}
}
示例11: postGetDocument
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public Object postGetDocument(Document document) throws Exception {
NodeList attachs = document.getDocumentElement().getElementsByTagName("attachment");
if (attachs != null)
for(int i=attachs.getLength()-1;i>=0;i--){
Element attach = (Element)attachs.item(i);
if (attach.getParentNode()==attach.getOwnerDocument().getDocumentElement())
return AttachmentManager.getAttachment(attach);
}
return null;
}
示例12: getParentNameSpaces
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Adds to ns the definitions from the parent elements of el
* @param el
* @param ns
*/
protected final void getParentNameSpaces(Element el, NameSpaceSymbTable ns) {
Node n1 = el.getParentNode();
if (n1 == null || Node.ELEMENT_NODE != n1.getNodeType()) {
return;
}
//Obtain all the parents of the element
List<Element> parents = new ArrayList<Element>();
Node parent = n1;
while (parent != null && Node.ELEMENT_NODE == parent.getNodeType()) {
parents.add((Element)parent);
parent = parent.getParentNode();
}
//Visit them in reverse order.
ListIterator<Element> it = parents.listIterator(parents.size());
while (it.hasPrevious()) {
Element ele = it.previous();
handleParent(ele, ns);
}
parents.clear();
Attr nsprefix;
if (((nsprefix = ns.getMappingWithoutRendered(XMLNS)) != null)
&& "".equals(nsprefix.getValue())) {
ns.addMappingAndRender(
XMLNS, "", getNullNode(nsprefix.getOwnerDocument()));
}
}
示例13: getWsdlBackupDir
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
protected String getWsdlBackupDir(Element element) throws Exception {
String backupDir = super.getWsdlBackupDir(element);
Element connectorNode = (Element) element.getParentNode();
NodeList properties = connectorNode.getElementsByTagName("property");
Element pName = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "name");
String connectorName = (String) XMLUtils.readObjectFromXml((Element) XMLUtils.findChildNode(pName, Node.ELEMENT_NODE));
backupDir += "/" + connectorName;
return backupDir;
}
示例14: findElementWithModule
import org.w3c.dom.Element; //导入方法依赖的package包/类
/** Find a matching web element - useful for updating or deleting an existing element */
protected Element findElementWithModule(Document doc) {
NodeList moduleNodeList = doc.getElementsByTagName("java");
Element matchingModuleElement = findElementWithMatchingText(module, moduleNodeList);
if (matchingModuleElement != null) {
return (Element) matchingModuleElement.getParentNode();
} else {
return null;
}
}
示例15: initNamespaceSupport
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Initialize namespace support by collecting all of the namespace
* declarations in the root's ancestors. This is necessary to
* support schemas fragments, i.e. schemas embedded in other
* documents. See,
*
* https://jaxp.dev.java.net/issues/show_bug.cgi?id=43
*
* Requires the DOM to be created with namespace support enabled.
*/
private void initNamespaceSupport(Element schemaRoot) {
fNamespaceSupport = new SchemaNamespaceSupport();
fNamespaceSupport.reset();
Node parent = schemaRoot.getParentNode();
while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE
&& !parent.getNodeName().equals("DOCUMENT_NODE"))
{
Element eparent = (Element) parent;
NamedNodeMap map = eparent.getAttributes();
int length = (map != null) ? map.getLength() : 0;
for (int i = 0; i < length; i++) {
Attr attr = (Attr) map.item(i);
String uri = attr.getNamespaceURI();
// Check if attribute is an ns decl -- requires ns support
if (uri != null && uri.equals("http://www.w3.org/2000/xmlns/")) {
String prefix = attr.getLocalName().intern();
if (prefix == "xmlns") prefix = "";
// Declare prefix if not set -- moving upwards
if (fNamespaceSupport.getURI(prefix) == null) {
fNamespaceSupport.declarePrefix(prefix,
attr.getValue().intern());
}
}
}
parent = parent.getParentNode();
}
}