Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

The JBoss OSGi Apache Xerces bundle

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

XML Parser Strategies

There are several ways of using an XML parser in an OSGi environment. Here are some strategies in descending order of preference

1 DocumentBuilderFactory service

The prefered way is to obtain a DocumentBuilderFactory service from the OSGi registry. In your bundle you setup a ServiceTracker and use the DocumentBuilderFactory that is given to you by the OSGi runtime. The jboss-osgi-xerces bundle registeres such a service when it is started.

2 DocumentBuilderFactory.newInstance()

In case you have a third party library that uses the DocumentBuilderFactory API and you cannot change that library to use strategy #1 you can wrap that library in a bundle and embed the 'META-INF/services/javax.xml.parsers.DocumentBuilderFactory' resource with the following content in it.


Your wrapper bundle must import the 'org.jboss.osgi.xml' package and you must set the thread context classloader before the library calls DocumentBuilderFactory.newInstance().

  ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
     factory = DocumentBuilderFactory.newInstance();

The document builder factory you get should be the one from jboss-osgi-xerces.

Something went wrong with that request. Please try again.