|
|
| 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:
- read an XML file and write it to an output stream.
- validate and parse XML data that contains an external entity reference by
using the XML registry to specify a local copy of the external entity.
- pass XML data between a client and a JSP via an HTTP POST.
- create an error handler to handle errors that occur while parsing invalid XML documents.
|
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:
- Build the example
- Configure the WebLogic server
- Run the example
- Set up your development shell as described in
Quick Start.
- 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:
- Compiles the Client.
- Compiles MyErrorHandler into the examples Web application directory.
- Copies the product.dtd file, which is the external entity referenced in the XML file, into the examples Web application directory.
- Copies the Entity_resolution.jsp file into the examples Web application directory.
- Compiles the JSP Entity_resolution.jsp into the WEB-INF\classes directory of the examples Web application directory.
This procedure shows how to register the external entity referenced in the
XML file with the WebLogic server.
- Start the WebLogic server with the examples
configuration in a new command shell.
- Invoke the Administration Console in your browser.
- Click to expand the Services node in the left pane.
- Right-click the XML node under the Services node and chose Configure a New XML Registry.
- Enter examplesXMLRegistry in the Name field.
- Click Create.
- Click to expand the examplesXMLRegistry node under the XML node in the left pane.
- Right-click the XMLEntitySpecRegistryEntry node and chose Configure a New XMLEntitySpecRegistryEntry.
- Enter a unique name in the Name field.
- Enter http://dev/products in the System Id field.
- Enter product.dtd in the Entity URI field.
- Click Create.
- Click the examplesServer node under the Server node in the left pane.
- Click the Services tab.
- Click the XML tab.
- Select examplesXMLRegistry as the XML registry that is associated with the examplesServer server in the XML Registry field.
- Click Apply.
Run the Example
- In your development shell, run the Client with the following command:
prompt> ant run_valid
- 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:
Copyright © 2002 BEA Systems, Inc. All Rights Reserved.