How to update xml files in java

后端 未结 4 1796
悲&欢浪女
悲&欢浪女 2020-12-17 18:00

I have a xml file call data.xml like the code below. The project can run from client side no problem and it can read the xml file. The problem I have now is I I want to writ

4条回答
  •  温柔的废话
    2020-12-17 18:11

    Underscore-java library can read xml to the linked hash map and regenerate xml after modification. I am the maintainer of the project. Live example

    import com.github.underscore.lodash.U;
    
    public class MyClass {
        public static void main(String args[]) {
            String xml = ""
            + ""
            + "       admin"
            + "       12345"
            + "       1"
            + "       90"
            + "       01/01/2013"
            + "       06/01/2013"
            + "       1110"
            + "    ";  
            java.util.Map object = U.fromXmlMap(xml);
            U.set(object, "data.startdate", "02/02/2013");
            U.set(object, "data.enddate", "07/02/2013");
            System.out.println(U.toXml(object)); 
        }
    }
    
    // 
    // 
    //   admin
    //   12345
    //   1
    //   90
    //   02/02/2013
    //   07/02/2013
    //   1110
    // 
    

提交回复
热议问题