| User's Guide for Xhsc | ||
|---|---|---|
| <<< Previous | Next >>> | |
Xhsc's processing engine can be used in your Java XML programs. When you use Xhsc in this manner, you must supply the DOM tree for an Xhsc specification, and then the DOM trees for one or more input documents. The Xhsc engine will modify the input document in place as it applies the Xhsc instructions from the specification.
To use Xhsc from a program, you must make the Xhsc package accessible to your code. This requires two things:
Copy the file hsc.jar to your JRE extensions directory, or add the file to your CLASSPATH.
Import the class xmlutil.xhsc.HSCProcessor.
The HSCProcessor class is your interface to Xhsc processing. To use it, follow these steps:
Create a new HSCProcessor object. The constructor takes no arguments.
Call the HSCProcessor method processSpecification on the DOM tree of your specification. This method takes two arguments: the DOM of the specification, and a boolean. If the boolean is true, then warning messages might be printed to System.err. This method returns the number of Xhsc instructions extracted from the specification DOM tree.
Call the HSCProcessor method processDocument on each of the input documents you want to modify. This method takes one argument: the DOM tree to be modified. It returns the DOM tree.
Each HSCProcessor object encapsulates a single set of Xhsc instructions, but it can apply those instructions to one or several successive documents. Note that HSCProcessor is not thread-safe. If you need to perform HSC processing in several threads, create a separate HSCProcessor object for each thread.
The example below shows some Java code that uses the Xhsc package.
Example 12. Java code that uses Xhsc
import xmlutil.xhsc.HSCProcessor;
...
...
public int processDocs(Document specdoc, Document indoc) {
Node outdoc;
HSCProcessor hp;
hp = new HSCProcessor();
int cnt;
cnt = hp.processSpecification(specdoc, true);
System.err.println("Got " + cnt + " HSC directives");
if (cnt > 0) {
message("Applying HSC directives to generate structure.");
outdoc = hp.processDocument(indoc);
}
else {
message("Skipping HSC processing.");
outdoc = indoc;
}
return writeOutputDocument(outdoc);
}
|
| <<< Previous | Home | Next >>> |
| Using Xhsc from the Command Line | References |