当前位置: 首页>>代码示例>>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;未经允许,请勿转载。