當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.renameNode方法代碼示例

本文整理匯總了Java中org.w3c.dom.Document.renameNode方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.renameNode方法的具體用法?Java Document.renameNode怎麽用?Java Document.renameNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.w3c.dom.Document的用法示例。


在下文中一共展示了Document.renameNode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: storeFileLocator

import org.w3c.dom.Document; //導入方法依賴的package包/類
public static void storeFileLocator (LinkedList<String> storedFileLocators, String iniFile ){
	Document doc= getXmlDocument(iniFile);
//	doc.getElementsByTagName(arg0)
	//System.out.println(storedFileLocators);
	Node fileLocatorNode = getElementByTagName (doc,"DEFINITIONFILELOCATORS");
	boolean tagUpdated=false;
	for (String fileLocator: storedFileLocators){//check if the file locator list contains file locator which are not stored in the ini setting 
	boolean fileLocatorIsStored=false; 
		for (int t = 0; t<fileLocatorNode.getChildNodes().getLength(); t++){
			 	if ( fileLocator.equals(fileLocatorNode.getChildNodes().item(t).getTextContent()) )
			 		fileLocatorIsStored=true;  
			 }
		if (!fileLocatorIsStored) {
			for (int tt = 0; tt<fileLocatorNode.getChildNodes().getLength(); tt++){
			 	if (fileLocatorNode.getChildNodes().item(tt).getNodeType()==1 ) 
			 		doc.renameNode( fileLocatorNode.getChildNodes().item(tt)
			 				,null,
			 				"FileLocator"+String.valueOf(Integer.valueOf(fileLocatorNode.getChildNodes().item(tt).getNodeName().substring(11))+1)  ); 
			 }
			Stack<Node> nodeStapel = new Stack<Node>(); 
			int childrenCount = fileLocatorNode.getChildNodes().getLength();
			for (int ttt = 0; ttt<childrenCount; ttt++){
			if (fileLocatorNode.getChildNodes().item( fileLocatorNode.getChildNodes().getLength()-1 ).getNodeType() == 1)//
				nodeStapel.push(fileLocatorNode.getChildNodes().item( fileLocatorNode.getChildNodes().getLength()-1 ));//Immer wird der Letzte genommen und auf dem Stack gesetzt, damit wird das letzte Kind auch das Letze in der neuen Reihe sein 
			fileLocatorNode.removeChild(fileLocatorNode.getChildNodes().item( fileLocatorNode.getChildNodes().getLength()-1 )); 
			//wird ein Kind removed und er hintel�sst danach eine Index-L�cke, wird die Kinder-Indexierung neu vergeben und das alte Kind 1 wird Kind 0  
			}
			Element neuesElement = doc.createElement("FileLocator0");
			neuesElement.appendChild(doc.createTextNode(fileLocator)  );
//			fileLocatorNode.appendChild(neuesElement);
			nodeStapel.push( neuesElement );//das neueste Element wird der erste FileLocator-tag sein  
			tagUpdated=true;
			childrenCount=1;
			while (!nodeStapel.isEmpty()&&childrenCount<=10){
				fileLocatorNode.appendChild(nodeStapel.pop());
				childrenCount++;
			}				
			//showMeTheDoc(fileLocatorNode, 0);
		}
	}
if (tagUpdated){
storeXmlDocToFile(iniFile, doc); 	  
 }
}
 
開發者ID:RaduMarcel,項目名稱:EspressoViews,代碼行數:45,代碼來源:QueryDefinitionParser.java

示例2: spreadNamespaces

import org.w3c.dom.Document; //導入方法依賴的package包/類
public static void spreadNamespaces(Node node, String tns, boolean overwrite) {
	Document doc = node instanceof Document ? (Document) node : node.getOwnerDocument();
	boolean isParent = false;
	while (node != null) {
		Node next = null;
		if (!isParent && node.getNodeType() == Node.ELEMENT_NODE) {
			if (node.getNamespaceURI() == null) {
				node = doc.renameNode(node, tns, node.getNodeName());
			} else {
				if (overwrite) {
					tns = node.getNamespaceURI();
				}
			}
			NamedNodeMap nodeMap = node.getAttributes();
			int nodeMapLengthl = nodeMap.getLength();
			for (int i = 0; i < nodeMapLengthl; i++) {
				Node attr = nodeMap.item(i);
				if (attr.getNamespaceURI() == null) {
					doc.renameNode(attr, tns, attr.getNodeName());
				}
			}
		}
		isParent = (isParent || (next = node.getFirstChild()) == null) && (next = node.getNextSibling()) == null;
		node = isParent ? node.getParentNode() : next;
		if (isParent && node != null) {
			if (overwrite) {
				tns = node.getNamespaceURI();
			}
		}
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:32,代碼來源:XMLUtils.java

示例3: testAddUser

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
 * Checking conflicting namespaces and use renameNode and normalizeDocument.
 * @see <a href="content/accountInfo.xml">accountInfo.xml</a>
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testAddUser() throws Exception {
    String resultFile = USER_DIR + "accountRole.out";
    String xmlFile = XML_DIR + "accountInfo.xml";

    // Copy schema for outputfile
    Files.copy(Paths.get(XML_DIR, "accountInfo.xsd"),
            Paths.get(USER_DIR, "accountInfo.xsd"),
            StandardCopyOption.REPLACE_EXISTING);
    MyErrorHandler eh = new MyErrorHandler();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
    dbf.setNamespaceAware(true);
    dbf.setValidating(true);

    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    docBuilder.setErrorHandler(eh);

    Document document = docBuilder.parse(xmlFile);
    Element sell = (Element) document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Sell").item(0);
    Element role = (Element) sell.getParentNode();

    Element buy = (Element) document.renameNode(sell, PORTAL_ACCOUNT_NS, "acc:Buy");
    role.appendChild(buy);

    DOMImplementationLS impl
            = (DOMImplementationLS) DOMImplementationRegistry
                    .newInstance().getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();


    try(FileOutputStream output = new FileOutputStream(resultFile)) {
        MyDOMOutput mydomoutput = new MyDOMOutput();
        mydomoutput.setByteStream(output);
        writer.write(document, mydomoutput);
    }

    docBuilder.parse(resultFile);
    assertFalse(eh.isAnyError());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:48,代碼來源:UserController.java


注:本文中的org.w3c.dom.Document.renameNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。