/* SYSTEM.OUT.PRINTLN ("2323");
Documentbuilderfactory factory = Documentbuilderfactory.newinstance ();
Documentbuilder Docbuilder = Factory.newdocumentbuilder ();
Document parse = Docbuilder
. Parse (New File ("Src/prodquery.xml"));
Element CreateElement2 = Parse.createelement ("");
Element createelement = parse.createelement ("Products");
Node item2 = Parse.getchildnodes (). Item (Parse.getchildnodes (). GetLength ()-1);
For (String Item:map.keySet ()) {
Loop Add to Products
System.out.println ("Tianjia1");
Element Clidren = parse.createelement ("Product");
Attr CreateAttribute = Parse.createattribute ("name");
Createattribute.setnodevalue (item);
Attr CreateAttribute2 = Parse.createattribute ("value");
Createattribute2.setnodevalue (Map.get (item));
Clidren.setattributenode (CreateAttribute);
Clidren.setattributenode (CREATEATTRIBUTE2);
Createelement.appendchild (Clidren);
}
Add products to the root directory
Item2.appendchild (createelement);
Create a Transformerfactory object
Transformerfactory tfactory = Transformerfactory.newinstance ();
Get an Action object
Transformer Transformer = Tfactory.newtransformer ();
Setup, this is the code.
Transformer.setoutputproperty (outputkeys.encoding, "UTF-8");
//
Domsource Source = new Domsource (parse);
SYSTEM.OUT.PRINTLN ("Change Document");
Streamresult result = new Streamresult (New File ("Src/prodquery.xml"));
To wrap an XML file
Transformer.setoutputproperty (outputkeys.indent, "yes");
Transformer.setoutputproperty ("{Http://xml.apache.org/xslt}indent-amount", "4");
Transformer.transform (source, result); */
Updating nodes in XML