org.w3c.dom.bootstrap


1. Creating a new DOM document:

import org.w3c.dom.*;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;

// Get the DOM implementation registry
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();

// Get the DOM implementation for XML
DOMImplementation impl = registry.getDOMImplementation("XML");

// Create a new DOM document
Document document = impl.createDocument(null, "root", null);

2. Parsing an XML document:

import org.w3c.dom.*;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.xml.sax.InputSource;

// Get the DOM implementation registry
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();

// Get the DOM implementation for XML
DOMImplementation impl = registry.getDOMImplementation("XML");

// Create a new DOM document
Document document = impl.createDocument(null, "root", null);

// Parse the XML document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document parsedDocument = builder.parse(new InputSource("my-document.xml"));

3. Creating a new DOM element:

4. Adding a new DOM element to a document:

5. Removing a DOM element from a document:

6. Creating a new DOM attribute:

7. Adding a new DOM attribute to an element:

8. Removing a DOM attribute from an element:

9. Creating a new DOM text node:

10. Adding a new DOM text node to an element:

11. Removing a DOM text node from an element: