///////////////////////////////////////////////////////////////////////
        // Implementation

        protected virtual void SetBaseHref(string url)
        {
            Debug.Assert((url != null) && (url.Length != 0),
                         "invalid base url");
            try {
                IHTMLBaseElement       baseElem = null;
                IHTMLElementCollection allCollection;
                IHTMLDOMNode           headNode;

                // We initialized mshtml using IPersistStreamInit::InitNew, which does not
                // create a base element. Check in debug.
#if DEBUG
                allCollection = (IHTMLElementCollection)previewDocument.GetAll().Tags("BASE");
                if ((allCollection != null) && (allCollection.GetLength() > 0))
                {
                    baseElem = (IHTMLBaseElement)allCollection.Item(0, null);
                }
                Debug.Assert(baseElem == null,
                             "did not expect an existing <BASE> element");
                baseElem      = null;
                allCollection = null;
#endif // DEBUG

                baseElem = (IHTMLBaseElement)previewDocument.CreateElement("BASE");
                if (baseElem != null)
                {
                    allCollection = (IHTMLElementCollection)previewDocument.GetAll().Tags("HEAD");
                    Debug.Assert((allCollection != null) && (allCollection.GetLength() > 0),
                                 "preview document does not have a HEAD element!");
                    headNode = (IHTMLDOMNode)allCollection.Item(0, null);
                    headNode.AppendChild((IHTMLDOMNode)baseElem);

                    baseElem.SetHref(url);
                }
            }
            catch (Exception e) {
                Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "Exception caught while setting preview base url:\n\t" + e.ToString());
            }
        }