WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.xml.entityresolution

This example demonstrates how to register an external entity, in this case a DTD, in the XML registry of the WebLogic server and how the server uses the local copy of the DTD when it parses and validates the document that contains the external entity reference.

See:
          Description

Class Summary
MyErrorHandler This class handles any errors encountered while parsing an XML document.
 

Package examples.xml.entityresolution Description

This example demonstrates how to register an external entity, in this case a DTD, in the XML registry of the WebLogic server and how the server uses the local copy of the DTD when it parses and validates the document that contains the external entity reference.

In the example, the JSP Entity_resolution.jsp receives an XML file over HTTP from a Client. This XML file has a reference to an external entity. Before running the example, you must register the external entity using the Administration console. When you run the example, the external entity is resolved during the parsing and validating of the document. The JSP uses the DOM API to parse and validate the XML document.

The example also provides an invalid XML file to show how you can create an error handler to detect parser errors.

The example illustrates how to:

Additional Resources for examples.xml.entityresolution
Entity_resolution.jsp The JSP that receives the XML data from the Java Client, parses it and sends the acknowledgement back to the Client over HTTP.
product.xml The XML file that contains the exteranl entity reference that is passed between Java Client and the JSP over HTTP.
product_not_valid.xml The invalid XML file (missing attribute) that is passed between the Java Client and the JSP over HTTP.
 

The following section describes how to build and run the example:

  1. Build the example
  2. Configure the WebLogic server
  3. Run the example

Build the example

  1. Set up your development shell as described in Quick Start.

  2. Compile the example by executing the Java ant command:
     prompt> ant  
    The Java ant command uses the build.xml file, located in the SAMPLES_HOME\server\src\examples\xml\entityresolution directory, to build the example. The Java Ant command performs the following steps:

    1. Compiles the Client.
    2. Compiles MyErrorHandler into the examples Web application directory.
    3. Copies the product.dtd file, which is the external entity referenced in the XML file, into the examples Web application directory.
    4. Copies the Entity_resolution.jsp file into the examples Web application directory.
    5. Compiles the JSP Entity_resolution.jsp into the WEB-INF\classes directory of the examples Web application directory.

Configure the WebLogic Server

This procedure shows how to register the external entity referenced in the XML file with the WebLogic server.

  1. Start the WebLogic server with the examples configuration in a new command shell.
  2. Invoke the Administration Console in your browser.
  3. Click to expand the Services node in the left pane.
  4. Right-click the XML node under the Services node and chose Configure a New XML Registry.
  5. Enter examplesXMLRegistry in the Name field.
  6. Click Create.
  7. Click to expand the examplesXMLRegistry node under the XML node in the left pane.
  8. Right-click the XMLEntitySpecRegistryEntry node and chose Configure a New XMLEntitySpecRegistryEntry.
  9. Enter a unique name in the Name field.
  10. Enter http://dev/products in the System Id field.
  11. Enter product.dtd in the Entity URI field.
  12. Click Create.
  13. Click the examplesServer node under the Server node in the left pane.
  14. Click the Services tab.
  15. Click the XML tab.
  16. Select examplesXMLRegistry as the XML registry that is associated with the examplesServer server in the XML Registry field.
  17. Click Apply.

Run the Example

  1. In your development shell, run the Client with the following command:
      prompt> ant run_valid  

  2. Use the following command to run the Client with the product_not_valid.xml file to demonstrate what happens when a parsing error occurs. Check the server shell for the parsing error.
      prompt> ant run_not_valid  

There's More...

Read more about:


Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.