Bloom.Book.HtmlDom.MigrateEditableData C# (CSharp) Method

MigrateEditableData() private method

Replace page in its parent with an element which is a clone of template, but with the contents of page transferred as far as possible. Retain the id of the page. Set its lineage to the supplied value
private MigrateEditableData ( XmlElement page, XmlElement template, string lineage ) : string
page System.Xml.XmlElement
template System.Xml.XmlElement
lineage string
return string
        internal string MigrateEditableData(XmlElement page, XmlElement template, string lineage)
        {
            var newPage = (XmlElement) page.OwnerDocument.ImportNode(template, true);
            page.ParentNode.ReplaceChild(newPage, page);
            newPage.SetAttribute("id", page.Attributes["id"].Value);
            var oldLineageAttr = page.Attributes["data-pagelineage"];
            var oldLineage = oldLineageAttr == null ? "" : oldLineageAttr.Value;
            newPage.SetAttribute("data-pagelineage", lineage);

            //preserve the data-page attribute of the old page, which will normally be empty or missing
            var dataPageValue = page.GetAttribute("data-page");
            if(string.IsNullOrEmpty(dataPageValue))
            {
                newPage.RemoveAttribute("data-page");
            }
            else
            {
                newPage.SetAttribute("data-page", dataPageValue); //the template has these as data-page='extra'
            }

            // migrate text
            MigrateChildren(page, "bloom-translationGroup", newPage);
            // migrate images
            MigrateChildren(page, "bloom-imageContainer", newPage);
            return oldLineage;
        }