AODL.Document.Styles.MasterStyles.MasterPageFactory.FillFromXMLDocument C# (CSharp) Method

FillFromXMLDocument() public method

Fill/read the existing master page styles.
public FillFromXMLDocument ( TextDocument textDocument ) : void
textDocument AODL.Document.TextDocuments.TextDocument The owner text document.
return void
		public void FillFromXMLDocument(TextDocument textDocument)
		{
			try
			{
				TextMasterPageCollection txtMPCollection = new TextMasterPageCollection();
				XmlNodeList masterPageNodes = textDocument.XmlDoc.SelectNodes(
					"//style:master-page", textDocument.NamespaceManager);
				if (masterPageNodes != null)
				{
					foreach(XmlNode mpNode in masterPageNodes)
					{
						// Build the master page
						TextMasterPage txtMasterPage = new TextMasterPage(textDocument, mpNode);
						// Even if there is no usage of header within the master page style,
						// but of course there exists the header:style node, so we create
						// the TextPageHeader.
						txtMasterPage.TextPageHeader = new TextPageHeader();
						txtMasterPage.TextPageHeader.TextDocument = textDocument;
						txtMasterPage.TextPageHeader.TextMasterPage = txtMasterPage;
						// see comment above its the same procedure
						txtMasterPage.TextPageFooter = new TextPageFooter();
						txtMasterPage.TextPageFooter.TextDocument = textDocument;
						txtMasterPage.TextPageFooter.TextMasterPage = txtMasterPage;
						
						// Build header content
						XmlNode headerNode = mpNode.SelectSingleNode("//style:header", textDocument.NamespaceManager);
						if (headerNode != null)
						{
							txtMasterPage.TextPageHeader.ContentNode = headerNode;
							ContentCollection contents = GetContentHeaderFooter(headerNode, textDocument);
							if (contents != null) 
							{
								headerNode.RemoveAll();
								foreach(IContent iContent in contents) 
								{
									txtMasterPage.TextPageHeader.ContentCollection.Add(iContent);
								}
							}
						}

						// Build footer content
						XmlNode footerNode = mpNode.SelectSingleNode("//style:footer", textDocument.NamespaceManager);
						if (footerNode != null)
						{
							txtMasterPage.TextPageFooter.ContentNode = footerNode;
							ContentCollection contents = GetContentHeaderFooter(footerNode, textDocument);
							if (contents != null) 
							{
								footerNode.RemoveAll();
								foreach(IContent iContent in contents) 
								{
									txtMasterPage.TextPageFooter.ContentCollection.Add(iContent);
								}
							}
						}

						// Build master page layout
						XmlNode txtPageLayoutNode = textDocument.XmlDoc.SelectSingleNode(
							"//style:page-layout[@style:name='"+txtMasterPage.PageLayoutName+"']",
							textDocument.NamespaceManager);
						if (txtPageLayoutNode != null)
						{
							// Build master page layout properties
							XmlNode txtPageLayoutPropNode = txtPageLayoutNode.SelectSingleNode(
								"//style:page-layout-properties", textDocument.NamespaceManager);
							if (txtPageLayoutPropNode != null)
							{
								TextPageLayout txtPageLayout = new TextPageLayout(
									textDocument, txtPageLayoutNode, txtPageLayoutPropNode);
								txtMasterPage.TextPageLayout = txtPageLayout;
							}
							// Build master page header layout
							XmlNode txtHeaderStyleNode = txtPageLayoutNode.SelectSingleNode(
								"//style:header-style", textDocument.NamespaceManager);
							if (txtHeaderStyleNode != null)
							{
								txtMasterPage.TextPageHeader.StyleNode = txtHeaderStyleNode;
								if (txtHeaderStyleNode.FirstChild != null
									&& txtHeaderStyleNode.FirstChild.Name == "style:header-footer-properties")
									txtMasterPage.TextPageHeader.PropertyNode = txtHeaderStyleNode.FirstChild;
							}
							// Build master page footer layout
							XmlNode txtFooterStyleNode = txtPageLayoutNode.SelectSingleNode(
								"//style:footer-style", textDocument.NamespaceManager);
							if (txtFooterStyleNode != null)
							{
								txtMasterPage.TextPageFooter.StyleNode = txtFooterStyleNode;
								if (txtFooterStyleNode.FirstChild != null
									&& txtFooterStyleNode.FirstChild.Name == "style:header-footer-properties")
									txtMasterPage.TextPageFooter.PropertyNode = txtFooterStyleNode.FirstChild;
							}
						}
						
						txtMPCollection.Add(txtMasterPage);
					}
				}
				textDocument.TextMasterPageCollection = txtMPCollection;
			}
			catch(Exception)
			{
				throw;
			}
		}