Changing node name of xml-node with Java

后端 未结 5 1568
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-30 05:42

I have following scenario: I have a XML-Document, e.g. like this



    

        
5条回答
  •  太阳男子
    2020-12-30 06:17

    You could use an XSL Transformation (XSLT) for this:

    
    
      
       
        
          
          
        
      
       
        
          
          
        
      
    
    

    This can be used with the javax.xml.transform package (Java 1.4 and above):

    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer(new StreamSource(
        new File("RenameTag.xslt")));
    transformer
        .transform(new DOMSource(document), new StreamResult(System.out));
    

    See DOMResult if you want a Document as the output.

提交回复
热议问题