Quark XML Author 10.0 — System Admin Guide

Implementing a Custom XML Resolver

Implementation Overview

Although Quark XML Author uses an internal XML Resolver to resolve such items as DTD declarations and Schema references, it may be necessary to implement a custom resolver.

A custom resolver is implemented via an external DLL that is called by an Extensibility Interface method. The custom resolver must implement the IXmlResolverProvider interface, shown below.

public interface IXmlResolverProvider
{
    XmlResolver GetResolver(XmlAuthorOperationType opType, string input);
}

The XMLAuthorOperationType is an enumeration that denotes what operation is being performed, allowing the IXmlResolverProvider.GetResolver method to determine the appropriate XmlResolver to return:

public enum XmlAuthorOperationType
{
    Transform,      // import/export operations, such as when a document is first loaded.
    Internal,       // All internal operations.
    XSLTTransform   // Used for loading XSLT stylesheets
}
  • Transform: This is specified when an initial document is loaded and a stylesheet is specified in the AppConfig's namespace section. It's also used when a document is exported either via the Save command, or Create/Display Renditions.

  • Internal: This is used for all internal processing. The interpretation of XmlAuthorOperationType is entirely dependent on the custom use case for which this Resolver is designed. It can choose to totally ignore the type of operation for which the resolver is requested and return a single resolver instance.

  • XSLTTransform: This is used when an XSLT transform is loaded:

XslCompiledTransform xsl = new XslCompiledTransform();

xsl.Load(xslPath, new XsltSettings(true, true), resolverProvider.GetResolver(XmlAuthorOperationTypes.XSLTTransfor));

A custom resolver DLL consists of at least two parts: the implementation of the IXmlResolverProvider interface and the class and method that will be called from the Quark XML Author Extensibility Interface. An example is shown below:

Public Class MyResolver
{
   public void GetACustomResolver(Delegate[] delegates)
  {
       //call the delegate here with a new instance of the IXmlResolverProvider implementation.
      SetXmlResolver sxr = delegates[0] as SetXmlResolver;
      Sxr(new MyXmlResolverProvider());
  }
}
 
//Sample custom resolver class that returns a XmlUrlResolver for all Quark XML Author internal operations and null otherwise..
Public class MyXmlResolverProvider : IXmlResolverProvider
{
   Public XmlResolver GetResolver(XmlAuthorOperationType opType, string input)
   {
        //return new XmlUrlResolver();
      If(opType == XmlAuthorOperationType.Internal)
                Return null; //No resolver for Quark XML Author internal operations.
     Else
                Return new XmlUrlResolver(); //return URL resolver for all other cases
   }
}

Finally, to implement the custom resolver, the EI method must be defined to call it. Typically, this method would be referenced in the <Connect> event in AppConfig.xml where this resolver will be used to set a global Resolver for all documents opened in Quark XML Author. An example is shown below.

<Method id="GetResolver" assembly="CustomResolver" class="MyResolver" method="GetACustomResolver">
  <Argument type="Delegates">
    <Delegate>SetXmlResolver</Delegate>
  </Argument>
</Method>