BizTalk Utilities CV ,   Jobs ,   Code library  
 
javax.xml.parsers.DocumentBuilder Class
SAX 2.0 Features and Properties
MSMQ Mode Tool
XML for Software Configuration
XML - Basics.
RTF to XML converter 1.2
Retriving XML from a Oracle Table using the XDK for PL/SQL
'AspDoc' - Documenting your ASP code with XML
Password Encryption
Inserting Data in XML format into a table using Oracle XML SQL Utility
Java Architecture for XML Binding
XML to JTree
QuickBooks XML SDK
x++: The World's First Full XML-Based Programming Language Released!
Mobile Internet
Applying XML Patterns
shortx: New C like Syntax for x++
Witango XML Execution Engine
Search using XPath in Java with a default namespace
X-Fetch Wrapper
<< XSLT
.NET and XML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :3156

 

The javax.xml.parsers.DocumentBuilderFactory Class

Super Class : java.lang.Object.

Members

Signature

Public methods

Object

getAttribute(String name)

boolean

isCoalescing()

boolean

isExpandEntityReferences()

boolean

isIgnoringComments()

boolean

isIgnoringElementContentWhitespace()

boolean

isNamespaceAware()

boolean

isValidating()

abstract  DocumentBuilder

newDocumentBuilder()

static DocumentBuilderFactory

newInstance()

abstract  void

setAttribute(String name, Object value)

void

setExpandEntityReferences(boolean expandEntityRef)

void

setIgnoringComments(boolean ignoreComments)

void

setIgnoringElementContentWhitespace(boolean whitespace)

void

setNamespaceAware(boolean awareness)

void

setValidating(boolean validating)

Overview

This class provides the factory that enables applications to create a parser to parse XML documents and also create DOM Document. This class is not thread safe and user should take care regarding creation of DocumentBuilderFactory and it is suggested to have one instance per Thread. This class is generally used to get javax.xml.parsers.DocumentBuilder instance and use that to produce a org.w3c.dom.Document.

Application code does not deal directly with specific parse implementation such as Xerces or Crimson. Instead you write code against abstract classes provided by JAXP apis. This level of indirection allows you to choose and pick among different implementation without even recompiling your application.

Method Overviews

Important methods of this class are newInstance(),   newDocumentBuilder(), setNamespaceAware(boolean awareness) and setValidating(boolean validating).

Example of newInstance()

This method is used to create an instance of DocumentBuilderFactory. This is a abstract class and newInstance method uses the lookup method to load appropriate DocumentBuilderFactory. Generally

·        Use the value of javax.xml.parsers.DocumentBuilderFactory system property.

You can set the system property as {your factory class} = your factory class impl (It  may be org.apache.crimson.jaxp.DocumentBuilderFactoryImpl or org.apache.xerces.jaxp.DocumentBuilderFactoryImpl).

·        IfJRE/lib/jaxp.properties exists, then look for a javax.xml.parsers.DocumentBuilderFactory = Implementation entry in the file.

·        Use a JAR file service provider to look for a file called META-INF/services/ javax.xml.parsers.DocumentBuilderFactory in any jar file on the CLASSPATH.

·        Use default javax.xml.parsers.DocumentBuilderFactory instance(org.apache.crimson.jaxp.DocumentBuilderFactoryImpl will be used as a default implementation).

By default, it loads org.apache.crimson.jaxp.DocumentBuilderFactoryImpl instance.

Example of newDocumentBuilder()

This method creates an instance of javax.xml.parsers.DocumentBuilder. You can use newDocument() method to create a org.w3c.dom.Document interface or use parse() method to parse xml from various xml sources. These input sources are InputStreams, Files, URLs, and SAX InputSources.

Example of setValidating(boolean)

This method is used to validate an xml document during parsing. By default it is false.

Example of setNamespaceAware(boolean). This method is used to provide namespace aware for the parser and by default it is false.

Example of How to Create DocumentBuilderFactory

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.DocumentBuilder;

import java.io.File;

public class MainClass {

  public MainClass() {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    try{

      DocumentBuilder docBuilder = factory.newDocumentBuilder();

      docBuilder.parse(Inputsource);

    }catch(javax.xml.parsers.ParserConfigurationException e){

      e.printStackTrace();

    }catch(java.io.IOException e){

      e.printStackTrace();

    }catch(org.xml.sax.SAXException e){

      e.printStackTrace();

    }

  }

  public static void main(String args[]){

  MainClass mainClass = new MainClass();

  }

}


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Integration Specialist Needed - Wor
Virtualization Server Infrastructur
A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En

View all Jobs (Add yours)
View all CV (Add yours)




Web Hosting
TMobile G1 Accessories
help desk support


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP