View RSS Feed

Java XML

Creating Blank DOM Document

Rate this Entry
by , 04-27-2012 at 05:09 PM (896 Views)
This tutorial shows you how to create blank DOM document. JAXP (Java API for XML Processing) is a Java interface that provides a standard approach to Parsing XML documents. With JAXP, we will use the Document BuilderFactory to create DocumentBuilder class.
The class DocumentBuilderFactory is responsible for creating new DOM parsers. Normally it is used to a DOM parser. Example is as follows:
Java Code:
 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 DocumentBuilder parser = factory.newDocumentBuilder();
 Document doc = parser.parse(myInputSource); //The parse function is used to parse existing xml document.
DocumentBuilderFactory uses the system property javax.xml.parsers.XmlDocumentParserFactory to find the class to load. So you can change the parser by calling:
Java Code:
 
System.setProperty("javax.xml.parsers.XmlDocumentParserFactory",
  "com.foo.myFactory");
The instance of the class DocumentBuilder is used to create a blank document. The newDocument()method of the class returns a blank DOM document.
Java Code:
Document doc = parser.newDocument();

Submit "Creating Blank DOM Document" to Facebook Submit "Creating Blank DOM Document" to Digg Submit "Creating Blank DOM Document" to del.icio.us Submit "Creating Blank DOM Document" to StumbleUpon Submit "Creating Blank DOM Document" to Google

Categories
DOM

Comments