Update the node instance code to xml, and the xml node instance code.

Source: Internet
Author: User

Update the node instance code to xml, and the xml node instance code.

Update node instance code to xml

/* 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 productsSystem cyclically. out. println ("tianjia1"); Element clivity = parse. createElement ("product"); Attr createAttribute = parse. createAttribute ("name"); createAttribute. setNodeValue (item); Attr createAttribute2 = parse. createAttribute ("value"); createAttribute2.setNodeValue (map. get (item); climit. setAttributeNode (createAttribute); cli.pdf. setAttributeNode (createAttribute2); createElement. appendChild (client);} // 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 (); // sets the transformer encoding. setOutputProperty (OutputKeys. ENCODING, "UTF-8"); // DOMSource source = new DOMSource (parse); System. out. println ("change File"); StreamResult result = new StreamResult (new File ("src/ProdQuery. xml "); // Let the xml file wrap transformer. setOutputProperty (OutputKeys. INDENT, "yes"); transformer. setOutputProperty ("{ http://xml.apache.org/xslt } Indent-amount "," 4 "); transformer. transform (source, result );*/

The above example code for updating nodes in xml is all the content that I have shared with you. I hope you can give me a reference and support the help house.

Related Article

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.