当前位置: 首页>>代码示例>>Java>>正文


Java Document.importNode方法代码示例

本文整理汇总了Java中org.w3c.dom.Document.importNode方法的典型用法代码示例。如果您正苦于以下问题:Java Document.importNode方法的具体用法?Java Document.importNode怎么用?Java Document.importNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Document的用法示例。


在下文中一共展示了Document.importNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addChildNodes

import org.w3c.dom.Document; //导入方法依赖的package包/类
private void addChildNodes(Document xmlDocument, Node parent,
						   List<Node> nodes) {
	Node copiedNode;
	for (int i = 0; i < nodes.size(); i++) {
		copiedNode = xmlDocument.importNode(nodes.get(i), true);
		parent.appendChild(copiedNode);
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:9,代码来源:ParseExternalElements.java

示例2: createCopy

import org.w3c.dom.Document; //导入方法依赖的package包/类
static protected void createCopy(Step step, Document doc, Element stepNode) throws EngineException {
	NodeList list = step.getContextValues();
	if (list != null) {
		int len = list.getLength();
		for (int i=0; i<len;i++) {
			Node node = list.item(i);
			if (node != null) {
				boolean shouldImport = !node.getOwnerDocument().equals(doc);
				Node child = shouldImport ? doc.importNode(node, true):node.cloneNode(true);
				if (child.getNodeType() == Node.ELEMENT_NODE) {
					stepNode.appendChild((Element) child);
				} else if (child.getNodeType() == Node.ATTRIBUTE_NODE) {
					stepNode.setAttribute(child.getNodeName(),child.getNodeValue());
				}
			}
		}
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:19,代码来源:XMLCopyStep.java

示例3: cloneSafely

import org.w3c.dom.Document; //导入方法依赖的package包/类
private static Element cloneSafely(Element el) { // #190845
    // #50198: for thread safety, use a separate document.
    // Using XMLUtil.createDocument is much too slow.
    synchronized (db) {
        Document dummy = db.newDocument();
        return (Element) dummy.importNode(el, true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:M2AuxilaryConfigImpl.java

示例4: cloneSafely

import org.w3c.dom.Document; //导入方法依赖的package包/类
private static Element cloneSafely(Element el) {
    // #50198: for thread safety, use a separate document.
    // Using XMLUtil.createDocument is much too slow.
    synchronized (db) {
        Document dummy = db.newDocument();
        return (Element) dummy.importNode(el, true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:AntProjectHelper.java

示例5: getConfigurationFragment

import org.w3c.dom.Document; //导入方法依赖的package包/类
public Element getConfigurationFragment(String elementName, String namespace, boolean shared) {
    Element el = find(shared, namespace, elementName);

    if (el != null) {
        Document dummy = XMLUtil.createDocument("test", null, null, null);
        return (Element) dummy.importNode(el, true);
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:AuxiliaryConfigBasedPreferencesProviderTest.java

示例6: getXpathData

import org.w3c.dom.Document; //导入方法依赖的package包/类
private Document getXpathData(Document document, String xPath) {
	if (document == null) {
		return null;
	}
	if (xPath == null) {
		return null;
	}

	try {
		Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
		Element root =  (Element) doc.createElement("root"); 
		doc.appendChild(root);
		
		NodeList nl = getXpathApi().selectNodeList(document, xPath);
		if (nl != null)
			for (int i = 0; i< nl.getLength(); i++) {
				Node node = doc.importNode(nl.item(i), true);
				Element elt = doc.getDocumentElement();
				if (node.getNodeType() == Node.ELEMENT_NODE) {
					elt.appendChild(node);
				}
				if (node.getNodeType() == Node.TEXT_NODE) {
					elt.appendChild(node);
				}
				if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
					elt.setAttribute(node.getNodeName() + "_" + i, node.getNodeValue());
				}
			}

		return doc;
	} catch (TransformerException e) {
		ConvertigoPlugin.logWarning("Error for xpath : '" + xPath + "'\r " + e.getMessage());
		return null;
	}
}
 
开发者ID:convertigo,项目名称:convertigo-eclipse,代码行数:36,代码来源:XpathEvaluatorComposite.java

示例7: setByPath

import org.w3c.dom.Document; //导入方法依赖的package包/类
public static void setByPath(Document doc, String path, Node in) {
    if (in.getNodeType() == Node.DOCUMENT_NODE) {
        in = in.getFirstChild();
    }
    Node node = getNodeByPath(doc, path, true);
    if (node == null) {
        throw new RuntimeException("no results for xpath: " + path);
    }
    Node newNode = doc.importNode(in, true);
    if (node.hasChildNodes() && node.getFirstChild().getNodeType() == Node.TEXT_NODE) {
        node.replaceChild(newNode, node.getFirstChild());
    } else {
        node.appendChild(newNode);
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:16,代码来源:XmlUtils.java

示例8: getImportedComponentFragment

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Given the target Node, return the DocumentFragment, imported into the
 * target Document
 * @param targetNode 
 */
protected final DocumentFragment getImportedComponentFragment(Node targetNode)
{
  Document targetDocument = targetNode.getOwnerDocument();
  
  // return a deep import
  return (DocumentFragment)targetDocument.importNode(_fragment, true);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:13,代码来源:AddComponentDocumentChange.java

示例9: importElement

import org.w3c.dom.Document; //导入方法依赖的package包/类
protected Element importElement(Element element) {
    Document document = getOwnerDocument();
    Document oldDocument = element.getOwnerDocument();
    if (!oldDocument.equals(document)) {
        return (Element) document.importNode(element, true);
    } else {
        return element;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ElementImpl.java

示例10: convertToSoapElement

import org.w3c.dom.Document; //导入方法依赖的package包/类
private  SOAPElement convertToSoapElement(Element element) throws SOAPException {

        if (element instanceof SOAPElement) {
            return (SOAPElement) element;
        }

        SOAPElement copy = createElement(
                                element.getLocalName(),
                                element.getPrefix(),
                                element.getNamespaceURI());

        Document ownerDoc = copy.getOwnerDocument();

        NamedNodeMap attrMap = element.getAttributes();
        for (int i=0; i < attrMap.getLength(); i++) {
            Attr nextAttr = (Attr)attrMap.item(i);
            Attr importedAttr = (Attr)ownerDoc.importNode(nextAttr, true);
            copy.setAttributeNodeNS(importedAttr);
        }


        NodeList nl = element.getChildNodes();
        for (int i=0; i < nl.getLength(); i++) {
            org.w3c.dom.Node next = nl.item(i);
            org.w3c.dom.Node imported = ownerDoc.importNode(next, true);
            copy.appendChild(imported);
        }

        return copy;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:SOAPFactoryImpl.java

示例11: writeToDOM

import org.w3c.dom.Document; //导入方法依赖的package包/类
private synchronized void writeToDOM(Node target, short type) {
    Document futureOwner = (type == XSAnnotation.W3C_DOM_ELEMENT) ?
            target.getOwnerDocument() : (Document)target;
    DOMParser parser = fGrammar.getDOMParser();
    StringReader aReader = new StringReader(fData);
    InputSource aSource = new InputSource(aReader);
    try {
        parser.parse(aSource);
    }
    catch (SAXException e) {
        // this should never happen!
        // REVISIT:  what to do with this?; should really not
        // eat it...
    }
    catch (IOException i) {
        // ditto with above
    }
    Document aDocument = parser.getDocument();
    parser.dropDocumentReferences();
    Element annotation = aDocument.getDocumentElement();
    Node newElem = null;
    if (futureOwner instanceof CoreDocumentImpl) {
        newElem = futureOwner.adoptNode(annotation);
        // adoptNode will return null when the DOM implementations are not compatible.
        if (newElem == null) {
            newElem = futureOwner.importNode(annotation, true);
        }
    }
    else {
        newElem = futureOwner.importNode(annotation, true);
    }
    target.insertBefore(newElem, target.getFirstChild());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:XSAnnotationImpl.java

示例12: copyNodeWithoutNamespace

import org.w3c.dom.Document; //导入方法依赖的package包/类
private static void copyNodeWithoutNamespace(Document document, Node parentNode, Node sourceNode) {
	Node destinationNode;
	if (sourceNode instanceof Document) {
		destinationNode = parentNode;
	} else {
		if (sourceNode instanceof Element) {
			String localName = XMLUtils.getLocalName(sourceNode);
			destinationNode = document.createElement(localName);
			
			// Copy attributes
			NamedNodeMap attributes = sourceNode.getAttributes();
			for (int i = 0; i < attributes.getLength(); i++) {
				Node sourceAttribute = attributes.item(i);
				
				String prefix = XMLUtils.getPrefix(sourceAttribute);
				
				if (!prefix.equalsIgnoreCase("xmlns")) {
					((Element) destinationNode).setAttribute(XMLUtils.getLocalName(sourceAttribute),
							sourceAttribute.getNodeValue());
				}
			}
		} else {
			destinationNode = document.importNode(sourceNode, false);
		}
		
		parentNode.appendChild(destinationNode);
	}
	
	NodeList childNodes = sourceNode.getChildNodes();
	int len = childNodes.getLength();
	for (int i = 0; i < len; i++) {
		XMLUtils.copyNodeWithoutNamespace(document, destinationNode, childNodes.item(i));
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:35,代码来源:XMLUtils.java

示例13: createStepNodeSingleValue

import org.w3c.dom.Document; //导入方法依赖的package包/类
private void createStepNodeSingleValue(Document doc, Element stepNode, String key, Object value) {
	if (value instanceof NativeJavaObject) {
		value = ((NativeJavaObject) value).unwrap();
	}
	if (value instanceof XMLVector) {
		XMLVector<Object> nodeValues = GenericUtils.cast(value);
		for (Object object : nodeValues) {
			createStepNodeSingleValue(doc, stepNode, key, object);
		}
	} else if (value.getClass().isArray()) {
		int len = Array.getLength(value);
		for (int i = 0; i < len ; i++) {
			createStepNodeSingleValue(doc, stepNode, key, Array.get(value, i));
		}
	} else {
		Element var = doc.createElement(key.toString());
		stepNode.appendChild(var);

		// Structured variable
		if (value instanceof NodeList) {
			NodeList valueNodeList = (NodeList) value;
			int nlLen = valueNodeList.getLength();
			Document document = stepNode.getOwnerDocument();
			for (int i = 0; i < nlLen; i++) {
				Node nodeVarPart = valueNodeList.item(i);
				if (!nodeVarPart.getOwnerDocument().equals(document))
					nodeVarPart = document.importNode(nodeVarPart, true);
				var.appendChild(nodeVarPart);
			}
		} else {
			String nodeValue = value.toString();
			Node text = doc.createTextNode(nodeValue);
			var.appendChild(text);
		}
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:37,代码来源:InputVariablesStep.java

示例14: processDTree

import org.w3c.dom.Document; //导入方法依赖的package包/类
public Map<Integer, Dependency> processDTree(Node dTree){
	Map<Integer, Dependency> dep = new HashMap<Integer, Dependency>();
	// Tuple to position mapping
	Map<String, Integer> tupleMap = new HashMap<String, Integer>();
	// here starts the hard part
	try {
		Document D = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
		Node initialTree = D.importNode(dTree.getLastChild().getFirstChild(), true);
		D.appendChild(initialTree);
        //rebuild tree nodes
        NodeList treeNodes = D.getElementsByTagName("tree");
        ArrayList<Node> tNodes = new ArrayList<Node>();            
        for (int l = 0; l < treeNodes.getLength(); l++)
        {
            tNodes.add(treeNodes.item(l));    
        }
        for (int i = 0; i < tNodes.size(); i++)
        {
            Node treeNode = tNodes.get(i);
            String treeid = treeNode.getAttributes().getNamedItem("id").getNodeValue();
            TagTree tree  = subgrammar.get(treeid);
            int posi = this.getPosition(tree, tupleMap);
            // we process the "local" dependencies, ie co-anchors or lexical items
            this.getPositionsForTree(tree, posi, dep);
            
            if (treeNode.getParentNode().getParentNode() != null) {
            	// ie it is not the root node
            	// we retrieve the operation's Gorn address
                String opNode = treeNode.getParentNode().getAttributes().getNamedItem("node").getNodeValue();	                
            	// we retrieve the parent
                String parent = treeNode.getParentNode().getParentNode().getAttributes().getNamedItem("id").getNodeValue();
                //System.err.println(treeid + " --> " + parent);
                TagTree ptree = subgrammar.get(parent);
                // we retrieve the node cat:
                List<de.tuebingen.tree.Node> ln = new LinkedList<de.tuebingen.tree.Node>();
                ptree.findNode(ptree.getRoot(), opNode, ln);
                TagNode n  = ln.size() > 0 ? (TagNode) ln.get(0) : null;
                String cat = "";
                if (n != null) {
                	cat = n.getCategory();
                }
                int parentPosi = this.getPosition(ptree, tupleMap);
                if (parentPosi != posi && tree.getIsHead()) {
                	//System.err.println(" Dependency detected " + posi + " " + parentPosi);
                	dep.put(posi, new Dependency(parentPosi, cat));
                }
            } else {
            	// otherwise
            	//System.err.println(" Dependency detected " + posi + " " + 0);
            	dep.put(posi, new Dependency(0, "ROOT"));
            }
        }
	} catch (ParserConfigurationException e){
           System.err.println("Error while extracting dependencies: ");
           System.err.println(e.toString());
           StackTraceElement[] stack = e.getStackTrace();
           for (int i = 0; i < stack.length; i++)
           {
               System.err.println(stack[i]);
           }
	}
	//System.err.println(" ------ " );
	return dep;
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:65,代码来源:DependencyExtractor.java

示例15: displayTargetWsdlDom

import org.w3c.dom.Document; //导入方法依赖的package包/类
public void displayTargetWsdlDom(DatabaseObject dbo) {
	try {
		if (dbo instanceof Step) {
			Step step = (Step)dbo;
			String xpath = getSourceXPath();
			String anchor = step.getAnchor();
			Document stepDoc = null;
			
			Step targetStep = step;
			while (targetStep instanceof IteratorStep) {
				targetStep = getTargetStep(targetStep);
			}
			
			if (targetStep != null) {
				Project project = step.getProject();
				XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(project.getName(), Option.fullSchema);
				XmlSchemaObject xso = SchemaMeta.getXmlSchemaObject(schema, targetStep);
				if (xso != null) {
					stepDoc = XmlSchemaUtils.getDomInstance(xso);	
				}
			}
			
			if (stepDoc != null/* && !(targetStep instanceof IteratorStep)*/) { // stepDoc can be null for non "xml" step : e.g jIf
				Document doc = step.getSequence().createDOM();
				Element root = (Element)doc.importNode(stepDoc.getDocumentElement(), true);
				doc.replaceChild(root, doc.getDocumentElement());
				removeUserDefinedNodes(doc.getDocumentElement());
				boolean shouldDisplayDom = (!(!step.isXml() && (step instanceof StepWithExpressions) && !(step instanceof IteratorStep)));
				if ((doc != null) && (shouldDisplayDom)) {
					xpath = onDisplayXhtml(xpath);
					displayXhtml(doc);
					xpathEvaluator.removeAnchor();
					xpathEvaluator.displaySelectionXpathWithAnchor(twsDomTree, anchor, xpath);
					return;
				}
			}
		}
	} catch (Exception e) {
		ConvertigoPlugin.logException(e, StringUtils.readStackTraceCauses(e));
	}
	clean();
}
 
开发者ID:convertigo,项目名称:convertigo-eclipse,代码行数:43,代码来源:SourcePickerHelper.java


注:本文中的org.w3c.dom.Document.importNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。