Developing XML Applications with WebLogic Server 3-3
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document; ...
Obtain an instance of DocumentBuilderFactory. DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance; Specify a validating parser.
dbf.setValidatingtrue; Requires loading the DTD. Obtain an instance of a DocumentBuilder from the factory.
DocumentBuilder db = dbf.newDocumentBuilder; Parse the document.
Document doc = db.parseinputFile; ...
3.2.3 Parsing XML Documents in a Servlet
Support for the setAttribute and getAttribute methods was added to version 2.2 of the Java Servlet Specification. Attributes are objects associated with a request.
The request object encapsulates all information from the client request. In the HTTP protocol, this information is transmitted from the client to the server by the HTTP
headers and message body of the request.
With WebLogic Server, you can use the setAttribute and getAttribute methods to parse XML documents. Use the setAttribute method for SAX mode parsing and
the getAttribute method for DOM mode parsing, as described in Section 3.2.4,
Using the org.xml.sax.DefaultHandler Attribute to Parse a Document and
Section 3.2.5, Using the org.w3c.dom.Document Attribute to Parse a Document. Before you can use the setAttribute and getAttribute methods, however, you
must configure a WebLogic Server servlet filter called weblogic.servlet.XMLParsingHelper deployed by default on all WebLogic
Server instances as part of your Web application. Configure the servlet filter by adding the following elements to the web.xml deployment descriptor, located in the
WEB-INF directory of your Web application:
filter filter-nameXMLParsingHelperfilter-name
filter-classweblogic.servlet.XMLParsingHelperfilter-class filter
filter-mapping filter-nameXMLParsingHelperfilter-name
url-patternurl-pattern dispatcherREQUESTdispatcher
filter-mapping
Note: If you want to use a parser other than the default parser, you
must use the WebLogic Server Administration Console to specify it; otherwise the DocumentBuilderFactory.newInstance method
returns the default parser. For instructions about configuring WebLogic Server to use a parser other than the default parser, see
Section 9.2.1, Configuring a Parser or Transformer Other Than the Default.
3-4 Programming XML for Oracle WebLogic Server
For more information on servlet filters, see Filters in Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server.
3.2.4 Using the org.xml.sax.DefaultHandler Attribute to Parse a Document