Guest User

Untitled

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <header>
  3.  
  4. +<TAG1>*
  5. $<TAG2>**
  6. </TAG2>**
  7. +<TAG3>**
  8. $<TAG4>***
  9. </TAG4>***
  10. +<TAG5>***
  11. $<TAG6>****
  12. </TAG6>****
  13. $<TAG7>****
  14. </TAG7>****
  15. </TAG5>
  16. $<TAG8>
  17. </TAG8>
  18. </TAG3>**
  19. </TAG1>
  20.  
  21. </header>
  22.  
  23. File outputFile = new File("C:\Users\User\Documents\test.xml");
  24. DocumentBuilderFacotry dBFactory = DocumentBuilderFactory.newInstance();
  25. DocumentBuilder dB = dBFactory.newDocumentBuilder();
  26. org.w3c.dom.Document doc = dB.parse(outputFile);
  27.  
  28. org.w3c.dom.Element tagTest = doc.createEleement("tagTest");
  29. org.w3c.dom.Element node = doc.createElement("newNode");
  30. org.w3c.dom.Text text = doc.createTestNode("data");
  31. node.appendChild(text);
  32. tagTest.appendChild(node);
  33.  
  34.  
  35. TransformerFactory tFactory = TransformerFactory.newInstance();
  36. Transformer transformer = tFactory.newTransformer();
  37. transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
  38. transformer/setOutputProperty(OutputKeys.INDENT, "yes");
  39. Writer out = new StringWriter();
  40. transformer.transform(new DOMSource(doc), new StreamResult(outputFile));
  41. System.out.println(out.toString());
Add Comment
Please, Sign In to add comment