Start a new XML Document : DOM Edit « XML « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » XML » DOM Edit 
33. 3. 5. Start a new XML Document
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Utils {

  /**
   * Start a new XML Document.
   @param rootName The name of the Document root Element (created here)
   @return the Document
   @throws DomException
   */
  public static Document createXmlDocument(String rootName)  {

      Document  document  = getXmlDocumentBuilder().newDocument();
      Element   root      = document.createElement(rootName);

      document.appendChild(root);
      return document;

  
  }
  /**
   * Get a DOM Document builder.
   @return The DocumentBuilder
   @throws DomException
   */
  public static DocumentBuilder getXmlDocumentBuilder() {
    try {
      DocumentBuilderFactory factory;

      factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(false);

      return factory.newDocumentBuilder();

    catch (Exception e) {
      
    }
    return null;
  }

}
33. 3. DOM Edit
33. 3. 1. Creating an XML Document from a DOM Tree
33. 3. 2. Create Document with root QName
33. 3. 3. Create New Container
33. 3. 4. Document To String
33. 3. 5. Start a new XML Document
33. 3. 6. Adding a New Entry to the End of a List
33. 3. 7. A Method for Inserting a New Entry in a List
33. 3. 8. Locating a Node and Modifying Text
33. 3. 9. Locating a Node by Using Siblings
33. 3. 10. Deleting a Tree Node
33. 3. 11. Replacing a Tree Node: Replacing an Existing Node with a New One
33. 3. 12. Locating Elements by Tag Name
33. 3. 13. Duplicating a Portion of the Tree
33. 3. 14. Setting an Attribute
33. 3. 15. Deleting an Attribute
33. 3. 16. Moving and Copying Attributes
33. 3. 17. Locating a Node by an ID
33. 3. 18. Editing the Text of a Node
33. 3. 19. Modifying Text by Cutting and Pasting
33. 3. 20. Edit Text by Insertion and Replacement
33. 3. 21. Inserting a CDATASection Node
33. 3. 22. Normalize All of the Text in a Document
33. 3. 23. Moving Nodes between Documents: Copy a Node from One Parse Tree into Another
33. 3. 24. Editing by Using a Document Fragment: Creating a DocumentFragment Subtree and Appending to the Document
33. 3. 25. Inserting a Processing Instruction and Comment
33. 3. 26. Methods to Insert a Processing Instruction and a Comment
33. 3. 27. Changing the Name of a DOM Element
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.