In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "how to update nodes in xml", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to update nodes in xml" this article.
Update the instance code of the node 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 ()) {/ / loop added to productsSystem.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 an TransformerFactory object TransformerFactory tFactory = TransformerFactory.newInstance (); / / get an Operand Transformer transformer = tFactory.newTransformer () / / Settings, this is the code 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 xml files to transformer.setOutputProperty (OutputKeys.INDENT, "yes"); transformer.setOutputProperty ("{http://xml.apache.org/xslt}indent-amount"," 4 "); transformer.transform (source, result) * / above are all the contents of the article "how to update nodes in xml". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.