List of usage examples for org.w3c.dom Node getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:erwins.util.repack.xml.XMLBuilder.java
/** * Construct a new builder object that wraps the given XML document and node. * This constructor is for internal use only. * * @param myNode//from w w w . j a v a 2 s. com * the XML node that this builder node will wrap. This node may * be part of the XML document, or it may be a new element that is to be * added to the document. * @param parentNode * If not null, the given myElement will be appended as child node of the * parentNode node. */ protected XMLBuilder(Node myNode, Node parentNode) { this.xmlNode = myNode; if (myNode instanceof Document) { this.xmlDocument = (Document) myNode; } else { this.xmlDocument = myNode.getOwnerDocument(); } if (parentNode != null) { parentNode.appendChild(myNode); } }
From source file:jef.tools.XMLUtils.java
/** * ??Document?<br/>/*from w w w. j a v a 2 s . com*/ * ???Document? * * @param parent * * @param nodes * ??? */ public static void appendChild(Node parent, Node... nodes) { Document doc = parent.getOwnerDocument(); for (Node node : nodes) { if (node.getOwnerDocument() != doc) { parent.appendChild(doc.importNode(node, true)); } else { parent.appendChild(node); } } }
From source file:edu.stanford.epad.epadws.aim.AIMUtil.java
private static Node renameNodeNS(Node node, String newName, String xmlns) { Element newNode = node.getOwnerDocument().createElementNS(xmlns, newName); NamedNodeMap map = node.getAttributes(); for (int i = 0; i < map.getLength(); i++) { newNode.setAttribute(map.item(i).getNodeName(), map.item(i).getNodeValue()); }//from w w w. j a v a 2 s. c om NodeList tempList = node.getChildNodes(); for (int i = 0; i < tempList.getLength(); i++) { newNode.appendChild(tempList.item(i).cloneNode(true)); } return newNode; }
From source file:de.betterform.xml.dom.DOMUtil.java
/** * returns a canonical XPath locationpath for a given Node. Each step in the path will contain the positional * predicate of the Element. Example '/root[1]/a[1]/b[2]/c[5]/@d'. This would point to<br/> * to Attribute named 'd'<br/>// ww w.j av a 2 s . c o m * on 5th Element 'c"<br/> * on 2nd Element 'b'<br/> * on first Element a<br/> * which is a child of the Document Element. * * @param node the Node where to start * @return canonical XPath locationPath for given Node or the empty string if node is null */ public static String getCanonicalPath(Node node) { if (node == null) { return ""; } if (node.getNodeType() == Node.DOCUMENT_NODE) { return "/"; } //add ourselves String canonPath; String ns = node.getNamespaceURI(); String nodeName1 = node.getNodeName(); String nodeName2 = node.getLocalName(); if (ns != null && ns.equals("http://www.w3.org/1999/xhtml") && node.getNodeName().equals(node.getLocalName())) { canonPath = "html:" + node.getNodeName(); } else { canonPath = node.getNodeName(); } if (node.getNodeType() == Node.ATTRIBUTE_NODE) { canonPath = "@" + canonPath; } else if (node.getNodeType() == Node.ELEMENT_NODE) { int position = DOMUtil.getCurrentNodesetPosition(node); //append position if we are an Element canonPath += "[" + position + "]"; } //check for parent - if there's none we're root Node parent = null; if (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.TEXT_NODE) { parent = node.getParentNode(); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { parent = ((Attr) node).getOwnerElement(); } if (parent == null) { parent = node.getOwnerDocument().getDocumentElement(); } if (parent.getNodeType() == Node.DOCUMENT_NODE || parent.getNodeType() == Node.DOCUMENT_FRAGMENT_NODE) { canonPath = "/" + canonPath; } else { canonPath = DOMUtil.getCanonicalPath(parent) + "/" + canonPath; } return canonPath; }
From source file:jef.tools.XMLUtils.java
/** * XSD Schema// www . j a v a 2 s .c om * * @param node * DOM * @param schemaURL * XSDURL */ public static void setXsdSchema(Node node, String schemaURL) { Document doc; if (node.getNodeType() != Node.DOCUMENT_NODE) { doc = node.getOwnerDocument(); } else { doc = (Document) node; } Element root = doc.getDocumentElement(); if (schemaURL == null) { root.removeAttribute("xmlns:xsi"); root.removeAttribute("xsi:noNamespaceSchemaLocation"); } else { root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("xsi:noNamespaceSchemaLocation", schemaURL); } }
From source file:jef.tools.XMLUtils.java
/** * CDATA//w ww . ja v a 2 s. c o m * * @param node * * @param data * CDATA * @return ?CDATA */ public static CDATASection addCDataText(Node node, String data) { Document doc = null; if (node.getNodeType() == Node.DOCUMENT_NODE) { doc = (Document) node; } else { doc = node.getOwnerDocument(); } CDATASection e = doc.createCDATASection(data); node.appendChild(e); return e; }
From source file:jef.tools.XMLUtils.java
/** * ?/*w w w . jav a2 s . com*/ * * @param node * * @param data * * @return DOM */ public static Text setText(Node node, String data) { Document doc = null; if (node.getNodeType() == Node.DOCUMENT_NODE) { doc = (Document) node; } else { doc = node.getOwnerDocument(); } clearChildren(node, Node.TEXT_NODE); Text t = doc.createTextNode(data); node.appendChild(t); return t; }
From source file:jef.tools.XMLUtils.java
/** * ?/*from ww w .ja v a 2 s .co m*/ * * @param node * * @param comment * * @return Comment */ public static Comment addComment(Node node, String comment) { Document doc = null; if (node.getNodeType() == Node.DOCUMENT_NODE) { doc = (Document) node; } else { doc = node.getOwnerDocument(); } Comment e = doc.createComment(comment); node.appendChild(e); return e; }
From source file:jef.tools.XMLUtils.java
/** * ?/*from w ww .jav a 2 s.c o m*/ * * @param node * * @param tagName * ?? * @param nodeText * * @return Element */ public static Element addElement(Node node, String tagName, String... nodeText) { Document doc = null; if (node.getNodeType() == Node.DOCUMENT_NODE) { doc = (Document) node; } else { doc = node.getOwnerDocument(); } Element e = doc.createElement(tagName); node.appendChild(e); if (nodeText.length == 1) { setText(e, nodeText[0]); } else if (nodeText.length > 1) { setText(e, StringUtils.join(nodeText, '\n')); } return e; }
From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java
public void save(final Node node) { final Document document = node.getOwnerDocument(); final Element pluginElement = (Element) node; pluginElement.setAttribute(WizardSettingsManager.CLASS, this.getClass().getName()); final Element gaSettingsElement = document.createElement(GA_SETTINGS); node.appendChild(gaSettingsElement); saveGeneralParameters(gaSettingsElement); saveSelectors(gaSettingsElement);/*from ww w . j a va2 s .co m*/ saveOperators(gaSettingsElement); saveChromosome(gaSettingsElement); }