MoveMasterStyles() публичный статический Метод

Moves the master styles.
We will move the whole master style and master pages stuff from the style document to the text document. This is necessary for avoiding xml document owner errors. Notice: When the document will be saved this nodes have to move back to the styles document. Otherwise they wont work resp. diplayed not correct within OpenOffice.
public static MoveMasterStyles ( XmlDocument contentDocument, XmlNode nodeAutomaticStyles, XmlNode nodeMasterPages, XmlNamespaceManager namespaceMng ) : void
contentDocument System.Xml.XmlDocument The content document.
nodeAutomaticStyles System.Xml.XmlNode The node automatic styles.
nodeMasterPages System.Xml.XmlNode The node master pages.
namespaceMng System.Xml.XmlNamespaceManager The namespace MNG.
Результат void
Пример #1
0
 /// <summary>
 /// Rename master styles.
 /// </summary>
 /// <param name="styleDocument">The style document.</param>
 /// <param name="contentDocument">The content document.</param>
 /// <param name="namespaceMng">The namespace MNG.</param>
 public static void RenameMasterStyles(XmlDocument styleDocument, XmlDocument contentDocument, XmlNamespaceManager namespaceMng)
 {
     try
     {
         // Rename style names used in inside the master page
         // contents. This is necessary since OpenOffice create
         // duplicate style names.
         XmlNode automaticStyles = styleDocument.SelectSingleNode(
             "//office:automatic-styles", namespaceMng);
         XmlNode masterStyles = styleDocument.SelectSingleNode(
             "//office:master-styles", namespaceMng);
         if (automaticStyles != null && masterStyles != null && automaticStyles.HasChildNodes)
         {
             foreach (XmlNode styleNode in automaticStyles.ChildNodes)
             {
                 if (styleNode.Attributes["style:name"] != null)
                 {
                     // Look for associated content inside header and footer
                     string  styleName   = styleNode.Attributes["style:name"].Value;
                     string  family      = "text";                       // default text
                     XmlNode contentNode = null;
                     if (styleNode.Attributes["style:family"] != null && styleNode.Attributes["style:family"].Value.StartsWith("table"))
                     {
                         contentNode = masterStyles.SelectSingleNode(
                             "//*[@table:style-name = '" + styleName + "']", namespaceMng);
                         family = "table";
                     }
                     else
                     {
                         string xpath = "//*[@text:style-name = '" + styleName + "']";
                         contentNode = masterStyles.SelectSingleNode(
                             xpath, namespaceMng);
                     }
                     if (contentNode != null)
                     {
                         // This style name has to be changed
                         string master = "master";
                         styleNode.Attributes["style:name"].Value             = master + styleName;
                         contentNode.Attributes[family + ":style-name"].Value = master + styleName;
                     }
                 }
             }
             // Now, we move this nodes to avoid xml owner document errors
             MasterPageFactory.MoveMasterStyles(contentDocument, automaticStyles, masterStyles, namespaceMng);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }