Update nodes to xml, xml update nodes

Source: Internet
Author: User

Update nodes to xml, xml update nodes

/* 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 ()){
// Add to products cyclically
System. out. println ("tianjia1 ");
Element client= parse. createElement ("product ");
Attr createAttribute = parse. createAttribute ("name ");
CreateAttribute. setNodeValue (item );
Attr createAttribute2 = parse. createAttribute ("value ");
CreateAttribute2.setNodeValue (map. get (item ));
Climember. setAttributeNode (createAttribute );
Clidren. setAttributeNode (createAttribute2 );
CreateElement. appendChild (climember );
}
// Add products to the root directory
Item2.appendChild (createElement );
// Create a TransformerFactory object
TransformerFactory tFactory = TransformerFactory. newInstance ();
// Get an operation object
Transformer transformer = tFactory. newTransformer ();
// Seters. This is encoding.
Transformer. setOutputProperty (OutputKeys. ENCODING, "UTF-8 ");
//
DOMSource source = new DOMSource (parse );
System. out. println ("change file ");
StreamResult result = new StreamResult (new File ("src/ProdQuery. xml "));
// Wrap the xml file
Transformer. setOutputProperty (OutputKeys. INDENT, "yes ");
Transformer. setOutputProperty ("{http://xml.apache.org/?t=indent-amount", "4 ");
Transformer. transform (source, result );*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.