Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <header>
- +<TAG1>*
- $<TAG2>**
- </TAG2>**
- +<TAG3>**
- $<TAG4>***
- </TAG4>***
- +<TAG5>***
- $<TAG6>****
- </TAG6>****
- $<TAG7>****
- </TAG7>****
- </TAG5>
- $<TAG8>
- </TAG8>
- </TAG3>**
- </TAG1>
- </header>
- File outputFile = new File("C:\Users\User\Documents\test.xml");
- DocumentBuilderFacotry dBFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dB = dBFactory.newDocumentBuilder();
- org.w3c.dom.Document doc = dB.parse(outputFile);
- org.w3c.dom.Element tagTest = doc.createEleement("tagTest");
- org.w3c.dom.Element node = doc.createElement("newNode");
- org.w3c.dom.Text text = doc.createTestNode("data");
- node.appendChild(text);
- tagTest.appendChild(node);
- TransformerFactory tFactory = TransformerFactory.newInstance();
- Transformer transformer = tFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- transformer/setOutputProperty(OutputKeys.INDENT, "yes");
- Writer out = new StringWriter();
- transformer.transform(new DOMSource(doc), new StreamResult(outputFile));
- System.out.println(out.toString());
Add Comment
Please, Sign In to add comment