Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > XML applications > Use the XML API to perform operations > Performing basic operations > Overview of the XML API


The XFactory class

This is a quick overview of the methods that the XFactory class provides. The individual methods are discussed in detail in other articles in the information center.

The XFactory class is the main factory class for creating executables for XPath, XQuery, and XSLT. It is also the means for creating instances of other classes and factories such as the XStaticContext, XDynamicContext, XItemFactory, and XSequenceTypeFactory classes. An instance of XFactory maintains a set of registered schemas as well and can be validating or non-validating. A validating factory produces schema-aware executables and ensures that source documents get validated against the set of registered schemas before they are processed. If different sets of stylesheets or expressions need different sets of schemas, these can be kept separate by using more than one XFactory instance. An XFactory instance can be created by calling the static newInstance() method on the XFactory class. The instance is thread safe as long as the settings remain stable.

Here is an example of using the XFactory class.

// Create a new XFactory
XFactory factory = XFactory.newInstance();

// Create an XPath executable
XPathExecutable executable = factory.prepareXPath("/something/bar[2]");

// Create a new XStaticContext
XStaticContext staticContext = factory.newStaticContext();

// Create an XPath executable that is compiled in backwards
// compatibility mode staticContext.setXPathCompatibilityMode(XStaticContext.XPATH1_0_BC_COMPATIBILITY);
XPathExecutable bcExecutable = factory.prepareXPath("/something/bar[2]", staticContext);

// Set validating
factory.setValidating(true);

// Register a schema
factory.registerSchema(new StreamSource("myschema.xsd"));

// Create a schema aware XPath executable
staticContext = factory.newStaticContext();
staticContext.declareNamespace("something", "http://myschema/something");
XPathExecutable schemaExecutable =
   factory.prepareXPath("/something:something/bar[2] instance of element(bar, something:barType)", staticContext);

// Get the item factory for this XFactory (the two are related
// since the item factory depends on the schemas that are // registered with XFactory).
XItemFactory itemFactory = factory.getItemFactory();

+

Search Tips   |   Advanced Search