Beispiel #1
0
        public IHtmlTextNode AddTextNode(IHtmlContainer container, int index, string htmlText)
        {
            var node = _document.CreateTextNode(htmlText);

            AddNode(container, index, node);

            return(node.AsTextNode());
        }
Beispiel #2
0
    public static void Save(SnippetDocumentControl snippet, string filePath)
    {
        var doc = new HtmlAgilityPack.HtmlDocument();

        // use newlines with Stringbuilder so the document formats better than using @""
        var node = HtmlAgilityPack.HtmlNode.CreateNode(
            new System.Text.StringBuilder()
            .AppendLine("<html>")
            .AppendLine("<head></head>")
            .AppendLine($"<body>{snippet.Html}</body>")
            .AppendLine("</html>")
            .ToString()
            );

        doc.DocumentNode.AppendChild(node);

        var head = doc.DocumentNode.SelectSingleNode("//head");
        var body = doc.DocumentNode.SelectSingleNode("//body");

        // save CSS
        if (!string.IsNullOrWhiteSpace(snippet.CSS))
        {
            var s = doc.CreateElement("style");
            s.SetAttributeValue("type", "text/css");
            s.AppendChild(doc.CreateTextNode(snippet.CSS));
            head.AppendChild(s);
        }

        // save javascript
        if (!string.IsNullOrWhiteSpace(snippet.Javascript))
        {
            var s = doc.CreateElement("script");
            s.SetAttributeValue("type", "text/javascript");
            s.AppendChild(doc.CreateTextNode(snippet.Javascript));
            body.AppendChild(s);
        }

        AppendSnippetReferences(snippet, doc, head);

        doc.Save(filename: filePath);
    }
        public void Process([NotNull] RenderFieldArgs args)
        {
            if (args.FieldTypeKey != "rich text") return;

            if (Settings.DoNotExpandInLiveSite && Context.PageMode.IsNormal) return;
            
            var document = new HtmlDocument();
            document.LoadHtml(args.Result.FirstPart);
            var htmlNodeCollection = document.DocumentNode.SelectNodes("//span[@itemid]");
            
            if (htmlNodeCollection == null)
                return;
            
            foreach (var node in htmlNodeCollection)
            {
                var item = Context.Database.GetItem(node.Attributes["itemid"].Value);
                if (item == null) continue;

                var fieldValue = item[node.Attributes["field"].Value];

                if(Context.PageMode.IsNormal)
                {
                    var newnode = document.CreateTextNode(fieldValue);
                    node.ParentNode.ReplaceChild(newnode, node);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(fieldValue)) node.InnerHtml = fieldValue;

                    if (Context.PageMode.IsPageEditorEditing)
                    {
                        node.SetAttributeValue("style",Settings.SnippetStyle);
                    }    
                }
                
            }
            args.Result.FirstPart = document.DocumentNode.OuterHtml;
        }
Beispiel #4
0
 private static void ProcessCodeTags(HtmlDocument doc, Guid productID)
 {
     HtmlTextNode textNode;
     HtmlNodeCollection scripts = doc.DocumentNode.SelectNodes("//code");
     if (scripts != null)
     {
         foreach (HtmlNode node in scripts)
         {
             textNode = doc.CreateTextNode(Highlight.HighlightToHTML(node.InnerHtml, GetLanguage(node), true).Replace(@"class=""codestyle""", string.Format(@"class=""codestyle"" _wikiCodeStyle=""{0}""", GetLanguageAttrValue(node))));
             node.ParentNode.ReplaceChild(textNode, node);
         }
     }
 }
 HtmlNode CreateNodeWithTextContent(HtmlDocument doc, string elementTitle, string text)
 {
     HtmlNode node = doc.CreateElement(elementTitle);
     node.AppendChild(doc.CreateTextNode(text));
     return node;
 }
        private static string HighLightCode(string source)
        {
            //Escape HTML Symbols in code Tags

            var mcCode = rexCode.Matches(source);
            foreach (Match m in mcCode)
            {
                try
                {
                    var sCode = m.Groups[1].Value.Substring(m.Groups[1].Value.IndexOf(">", StringComparison.Ordinal) + 1);
                    source = source.Replace(sCode, EscapeHtml(sCode));
                }
                catch (Exception)
                {
                }
            }

            try
            {
                var doc = new HtmlDocument();
                doc.LoadHtml(source);
                var scripts = doc.DocumentNode.SelectNodes("//code");
                if (scripts != null)
                {
                    foreach (var node in scripts)
                    {
                        var textNode = doc.CreateTextNode(Highlight.HighlightToHTML(node.InnerHtml, GetLanguage(node), true).Replace(@"class=""codestyle""", string.Format(@"class=""codestyle"" _wikiCodeStyle=""{0}""", GetLanguageAttrValue(node))));
                        node.ParentNode.ReplaceChild(textNode, node);
                    }
                }
                return doc.DocumentNode.InnerHtml;
            }
            catch (Exception)
            {
                return source;
            }
        }
Beispiel #7
0
        private HtmlNode MakeNode(HtmlDocument doc, string tag, string mainAttr, string mainValue, Dictionary<string, string> createAttributes)
        {
            // can't create a new node for a script where the value is its id
            if (mainAttr == "src" && Regex.IsMatch(mainValue.ToLower(), "^[a-z][a-z0-9_\\-]*$"))
                return null;

            HtmlNode newNode = doc.CreateElement(tag);
            if (mainValue.StartsWith("javascript:"))
                newNode.AppendChild(doc.CreateTextNode(mainValue.After("javascript:")));
            else
                newNode.Attributes.Add(doc.CreateAttribute(mainAttr, mainValue));
            foreach (KeyValuePair<string, string> kvp in createAttributes)
                newNode.Attributes.Add(doc.CreateAttribute(kvp.Key, kvp.Value));
            return newNode;
        }
Beispiel #8
0
        /// <summary>
        /// Traverse the directory structure present in provided DirectoryModel and
        /// create HTML that will represent the directories and files that are found.
        /// </summary>
        /// <param name="directory">Directory containing subdirectories and articles.</param>
        /// <param name="listFileDoc">Object representing HTML document.</param>
        /// <param name="directoryDiv">Container representing div that will contain categories and articles.</param>
        /// <param name="isSourceDir">Bool representing whether directoryDiv, is parent directory of article directory structure.</param>
        static void GenerateHTML(DirectoryModel directory, HtmlDocument listFileDoc, HtmlNode directoryContainerDiv, 
            bool isSourceDir, ref int index, string categoriesUrlText)
        {
            // Hash directory path to be used as unique identifier for
            // folder div's id attribute
            index++;
            string encryptedPath = EncryptStrings.EncryptToMD5String(directory.Path);

            // Create div that will hold folder icon and directory name
            HtmlNode directoryDiv = listFileDoc.CreateElement("div");

            // Container for categories (subdirectories) and article links.
            directoryDiv.SetAttributeValue("class", "directory");
            directoryDiv.SetAttributeValue("id", encryptedPath);

            // Check whether or not current directory, is the parent node
            // of article directory structure (as this is first container to be seen)
            string style = isSourceDir ? String.Format("z-index: {0};", index) : String.Format("z-index: -{0}; display: none", index);
            directoryDiv.SetAttributeValue("style", style);

            // div to hold category header and links to roll back to previous views
            HtmlNode directoryCategoryContainer = listFileDoc.CreateElement("div");
            directoryCategoryContainer.SetAttributeValue("id", "category-container");

            // header for category section of directory div
            HtmlNode directoryHeader = listFileDoc.CreateElement("h2");
            directoryHeader.SetAttributeValue("class", "category-headers");

            // add text node for header
            HtmlNode categoryHeaderText = listFileDoc.CreateTextNode("Categories");
            directoryHeader.AppendChild(categoryHeaderText);
            directoryCategoryContainer.AppendChild(directoryHeader);

            // create div to hold category urls used to roll back to a
            //previous view
            HtmlNode categoryUrlDiv = listFileDoc.CreateElement("div");
            categoryUrlDiv.SetAttributeValue("class", "visited-categories-container");

            // add category url text
            HtmlNode categoryUrlText = listFileDoc.CreateTextNode(categoriesUrlText);
            categoryUrlDiv.AppendChild(categoryUrlText);
            directoryCategoryContainer.AppendChild(categoryUrlDiv);

            // add container for category header and links for rolling back to particular views
            // to the directory container div
            directoryDiv.AppendChild(directoryCategoryContainer);

            HtmlNode categoryRule = listFileDoc.CreateElement("hr");
            categoryRule.SetAttributeValue("class", "header-rule");
            directoryDiv.AppendChild(categoryRule);

            // update current url string to be used by subordinate categories
            string currentUrlName = Path.GetFileName(directory.Path);

            if (categoriesUrlText == String.Empty)
            {
                categoriesUrlText += @"<a href='#' onclick='rollBack("""")'>Home</a>";
            }
            else
            {
                categoriesUrlText += @" > <a href='#' onclick='rollBack(""" + encryptedPath + @""")'>" +
                                    currentUrlName + "</a>";
            }

            // Process subdirectories' contents and generate relevant
            // html.
            if (directory.Subdirectories.Count > 0)
            {
                foreach (DirectoryModel subdirectory in directory.Subdirectories)
                {
                    isSourceDir = false;

                    HtmlNode subDirectoryDiv = listFileDoc.CreateElement("div");
                    subDirectoryDiv.SetAttributeValue("class", "subdirectory");
                    subDirectoryDiv.SetAttributeValue("name", EncryptStrings.EncryptToMD5String(subdirectory.Path));
                    subDirectoryDiv.SetAttributeValue("onclick", "bringToFront(this)");

                    HtmlNode folderParagraph = listFileDoc.CreateElement("p");
                    folderParagraph.SetAttributeValue("class", "folder-name");

                    HtmlTextNode text = listFileDoc.CreateTextNode(Path.GetFileName(subdirectory.Path));
                    folderParagraph.AppendChild(text);

                    subDirectoryDiv.AppendChild(folderParagraph);

                    directoryDiv.AppendChild(subDirectoryDiv);

                    GenerateHTML(subdirectory, listFileDoc, directoryContainerDiv, isSourceDir, ref index, categoriesUrlText);
                }
            }

            // Container for links to show articles.
            HtmlNode clearFloatDiv = listFileDoc.CreateElement("div");
            clearFloatDiv.SetAttributeValue("style", "clear: both; width: 100%;");
            directoryDiv.AppendChild(clearFloatDiv);

            HtmlNode articleHeader = listFileDoc.CreateElement("h2");
            articleHeader.SetAttributeValue("class", "article-headers");

            HtmlNode articleHeaderText = listFileDoc.CreateTextNode("Articles");
            articleHeader.AppendChild(articleHeaderText);
            directoryDiv.AppendChild(articleHeader);

            HtmlNode articleRule = listFileDoc.CreateElement("hr");
            articleRule.SetAttributeValue("class", "header-rule");
            directoryDiv.AppendChild(articleRule);

            // Check that html files exist in directory and create representative
            // html links.
            if (directory.Files.Keys.Count > 0)
            {
                HtmlNode linkContainerNode = listFileDoc.CreateElement("ul");
                linkContainerNode.SetAttributeValue("class", "article-list");

                foreach (string key in directory.Files.Keys)
                {
                    HtmlNode listNode = listFileDoc.CreateElement("li");

                    HtmlNode linkNode = listFileDoc.CreateElement("a");

                    HtmlTextNode textNode = listFileDoc.CreateTextNode(directory.Files[key]);
                    linkNode.AppendChild(textNode);

                    string file = key;

                    linkNode.SetAttributeValue("id", EncryptStrings.EncryptToAESString(file));
                    linkNode.SetAttributeValue("href", "#");
                    linkNode.SetAttributeValue("onclick", "setContent(this.id)");

                    listNode.AppendChild(linkNode);

                    linkContainerNode.AppendChild(listNode);
                }

                directoryDiv.AppendChild(linkContainerNode);
            }

            directoryContainerDiv.AppendChild(directoryDiv);
        }
        private static HtmlNode GetExternalReferencesListNode(
            HtmlDocument document,
            IEnumerable<ExternalReference> externalReferences)
        {
            var list = document.CreateElement("ol");
            foreach (var reference in externalReferences)
            {
                var item = document.CreateElement("li");

                string referenceId = GetExternalReferenceId(reference.Index);

                var backLink = document.CreateElement("a");
                backLink.InnerHtml = "<strong>^</strong>";
                backLink.SetAttributeValue("href", "#" + referenceId + BackLinkReferenceIdSuffix);

                var externalLink = document.CreateElement("a");
                externalLink.InnerHtml = reference.Url;
                externalLink.SetAttributeValue("href", reference.Url);
                externalLink.SetAttributeValue("name", referenceId);

                item.AppendChild(backLink);
                item.AppendChild(document.CreateTextNode(" "));
                item.AppendChild(externalLink);

                list.AppendChild(item);
            }

            return list;
        }
Beispiel #10
0
    public string GetAppPage(Hashtable State, string page_name)
    {
        try
        {
            XmlDocument xmlDoc = GetStagingAppXml(State);

            //get background image
            XmlNode configuration_node = xmlDoc.SelectSingleNode("//configuration");
            XmlNode background_node = configuration_node.SelectSingleNode("background");
            if (background_node == null)
            {
                background_node = CreateNode(xmlDoc, configuration_node, "background");
            }
            XmlNode background_image_node = background_node.SelectSingleNode("image_source");
            if (background_image_node == null)
            {
                background_image_node = CreateNode(xmlDoc, background_node, "image_source", "https://s3.amazonaws.com/MobiFlexImages/apps/images/backgrounds/standard_w_header_iphone.jpg");
            }
            string background_image = background_image_node.InnerText;
            if (background_image.Contains("s3.amazonaws.com"))
            {
                if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE)
                    background_image = background_image.Replace("_iphone.", "_android.");
                State["BackgroundImageUrl"] = background_image;
            }
            else
            {
                background_image = background_image.Substring(background_image.LastIndexOf("/") + 1);
                if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE)
                    background_image = background_image.Replace("_iphone.", "_android.");

                State["BackgroundImageUrl"] = "https://s3.amazonaws.com/MobiFlexImages/apps/images/backgrounds/" + background_image;
            }

            XmlNode page_name_node = xmlDoc.SelectSingleNode("//pages/page/name[.  ='" + page_name + "']");
            if (page_name_node == null)
                return "";

            double y_factor = 1.0D;
            Util util = new Util();
            //if (State["SelectedDeviceType"].ToString() != State["SelectedDeviceView"].ToString())
            //{
           //     y_factor = util.GetYFactor(State);
           // }

            XmlNode page_node = page_name_node.ParentNode;
            XmlNode fields_node = page_node.SelectSingleNode("fields");
            if(fields_node == null)
                return "";

            XmlNodeList field_list = page_node.SelectSingleNode("fields").ChildNodes;
            HtmlDocument htmlDoc = new HtmlDocument();
            HtmlNode root = htmlDoc.DocumentNode;
            foreach (XmlNode field in field_list)
            {
                try
                {
                    //restrict certain cross use fields
                    if (State["SelectedAppType"].ToString() == Constants.NATIVE_APP_TYPE)
                    {
                        if (field.Name == "html_panel")
                            continue;
                    }

                    HtmlNode new_node = htmlDoc.CreateElement("div");
                    Hashtable field_map = ParseXmlToHtml(field);
                    SetCommonHtmlAttributes(htmlDoc, new_node, field_map, y_factor, field.Name);
                    HtmlAttribute title_attr = htmlDoc.CreateAttribute("title");
                    switch (field.Name)
                    {
                        case "image"://"<div title=\"MobiFlex Image\" id=\"{0}\"  type=\"get\" style=\"{2}\" ><img src=\"{1}\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Image";
                            string image_url = field_map["image_source"].ToString();
                            if (!field_map.ContainsKey("width")) //the xml does not have the width and height so use the width and height of the actual image
                            {
                                Size size = util.GetImageSize(image_url);
                                if (size != null)
                                {
                                    new_node.Attributes["style"].Value += "width:" + size.Width.ToString() + "px;height:" + size.Height.ToString() + "px;";
                                }
                            }
                            AddImageNode(htmlDoc, new_node, image_url);
                            break;
                        case "audio"://<div title=\"MobiFlex Audio\" id=\"{0}\" source=\"{1}\" style=\"{2}\"  ><img src=\"images/editor_images/audio_field.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Audio";
                            HtmlAttribute audio_source_attr = htmlDoc.CreateAttribute("source", field_map["audio_source"].ToString());
                            new_node.Attributes.Append(audio_source_attr);
                            AddImageNode(htmlDoc, new_node, "images/editor_images/audio_field.png");
                            break;
                        case "label": //"<div title=\"MobiFlex Label\" id=\"{0}\" style=\"{2}\" >{1}<img class=\"spacer\" src=\"images/spacer.gif\" style=\"position:relative;top:-16px;width:100%;height:100%\" /></div>"
                            title_attr.Value = "MobiFlex Label";
                            new_node.InnerHtml = field_map["text"].ToString();

                            //<img class=\"spacer\" src=\"images/spacer.gif\" style=\"position:relative;top:-16px;width:100%;height:100%\" />
                            HtmlNode label_img_node = htmlDoc.CreateElement("img");
                            HtmlAttribute label_img_src_attr = htmlDoc.CreateAttribute("src", "images/spacer.gif");
                            label_img_node.Attributes.Append(label_img_src_attr);

                            int label_font_size = -Convert.ToInt32(field_map["font_size"].ToString());
                            HtmlAttribute label_img_style_attr = htmlDoc.CreateAttribute("style", "position:relative;top:" + label_font_size.ToString() + "px;width:100%;height:100%");
                            label_img_node.Attributes.Append(label_img_style_attr);
                            new_node.AppendChild(label_img_node);
                            break;
                        case "text_field": //"<div title=\"MobiFlex TextField\" id=\"{0}\" type=\"{1}\" alt=\"{2}\"  style=\"{3}\" ><img src=\"images/editor_images/text_field.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex TextField";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/text_field.png");
                            string alt = "keyboard:";
                            if (field_map.ContainsKey("keyboard"))
                                alt +=  field_map["keyboard"].ToString() + ";";
                            else
                                alt +=  "default;";

                            if (field_map.ContainsKey("validation"))
                                alt += "validation:" + field_map["validation"].ToString();
                            else
                                alt += "validation:none";
                            HtmlAttribute alt_attr = htmlDoc.CreateAttribute("alt", alt);
                            new_node.Attributes.Append(alt_attr);
                            HtmlAttribute type_attr = htmlDoc.CreateAttribute("type", field_map["type"].ToString());
                            new_node.Attributes.Append(type_attr);
                            if (field_map["text"] != null)
                            {
                                HtmlAttribute text_attr = htmlDoc.CreateAttribute("text", EncodeStudioHtml(UnescapeXml(field_map["text"].ToString())));
                                new_node.Attributes.Append(text_attr);
                            }
                            break;
                        case "html_panel": //"<div title=\"MobiFlex HtmlPanel\" id=\"{0}\" style=\"{2}\" ><div style=\"width:98%;height:98%;overflow:hidden;background-color:#ffffff\">{1}</div></div>"
                            title_attr.Value = "MobiFlex HtmlPanel";
                            new_node.InnerHtml = HttpUtility.HtmlDecode(field_map["html"].ToString());
                            /* HtmlNode container_node = htmlDoc.CreateElement("div");
                             HtmlAttribute panel_style_attr = htmlDoc.CreateAttribute("style", " width:98%;height:98%;overflow:hidden;background-color:#ffffff");
                             container_node.Attributes.Append(panel_style_attr);
                              container_node.InnerHtml = HttpUtility.HtmlDecode(field_map["html"].ToString());
                            new_node.AppendChild(container_node);*/
                            break;
                        case "web_view": //<div title=\"MobiFlex WebView\" alt=\"MobiFlex WebView\" id=\"{0}\" style=\"position:absolute;z-index:{2};top:44px;left:0px;height:416px;width:320px;\" url=\"{1}\" ><iframe src='" + src + "' width='99%' height='99.4%' marginheight='0' marginwidth='0' scrolling='no' style='border-width:0;' /></div>"
                            title_attr.Value = "MobiFlex WebView";
                            if (field_map["url"] == null)
                                field_map["url"] = "";
                            HtmlAttribute url_attr = htmlDoc.CreateAttribute("url", field_map["url"].ToString());
                            new_node.Attributes.Append(url_attr);
                            if (field_map["url"].ToString().Length > 0)
                            {
                                HtmlNode iframe_node = htmlDoc.CreateElement("iframe");
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("src", field_map["url"].ToString()));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("width", "99%"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("height", "99.4%"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("marginheight", "0"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("marginwidth", "0"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("scrolling", "no"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("style", "border-width:0;"));
                                new_node.AppendChild(iframe_node);
                            }
                            else
                            {
                                HtmlNode div_node = htmlDoc.CreateElement("div");
                                String webview_url = "images/editor_images/WebView.jpg";
                                if (State["SelectedDeviceType"].ToString() == Constants.IPAD ||
                                   State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET)
                                    webview_url = "images/editor_images/WebView_ipad.jpg";
                                HtmlAttribute style2_attr = htmlDoc.CreateAttribute("style", "width:100%;height:100%;background-image:url('" + webview_url + "');background-repeat:no-repeat");
                                div_node.Attributes.Append(style2_attr);
                                new_node.AppendChild(div_node);
                            }
                            break;
                        case "button": //"<div title=\"MobiFlex Button\" style=\"{3}\" id=\"{0}\" align=\"center\"  submit=\"{1}\"><img src=\"https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png\" style=\"width:100%;height:100%\" /><p style=\"position:relative;top:-38px;\">{2}</p></div>"
                            title_attr.Value = "MobiFlex Button";

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText.Replace(":", "%3A"));
                                    }
                                    submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (submit.StartsWith("post"))
                                    {
                                        if (submit.Length >= 19)
                                            //submit = submit.Remove(0, 19).Insert(0, "post:response_page~");
                                            submit = submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (submit.Contains("next_page:"))
                                        submit = submit.Replace("next_page:", "next_page:page~");
                                    else if (submit.Contains("call:"))
                                        submit = submit.Replace("call:", "call:phone_field~");
                                }
                            }

                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute submit_attr = htmlDoc.CreateAttribute("submit", submit);
                            new_node.Attributes.Append(submit_attr);

                            //align=\"center\"
                            HtmlAttribute align_attr = htmlDoc.CreateAttribute("align", "center");
                            new_node.Attributes.Append(align_attr);

                            //<img src=\"https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png\" style=\"width:100%;height:100%\" />
                            HtmlNode img_node = htmlDoc.CreateElement("img");
                            HtmlAttribute img_src_attr = null;
                            if (field_map["image_source"] != null)
                                img_src_attr = htmlDoc.CreateAttribute("src", field_map["image_source"].ToString());
                            else
                                img_src_attr = htmlDoc.CreateAttribute("src", "https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png");

                            img_node.Attributes.Append(img_src_attr);

                            HtmlAttribute img_style_attr = htmlDoc.CreateAttribute("style", "width:100%;height:100%");
                            img_node.Attributes.Append(img_style_attr);
                            new_node.AppendChild(img_node);

                            //<p style=\"position:relative;top:-38px;\">{2}</p>
                            HtmlNode p_node = htmlDoc.CreateElement("p");
                            HtmlNode text_node = null;
                            if (field_map["text"] != null)
                                text_node = htmlDoc.CreateTextNode(field_map["text"].ToString());
                            else
                                text_node = htmlDoc.CreateTextNode("");

                            p_node.AppendChild(text_node);
                            //top = (-ph/2) -(3*ah/2);
                            int height = Convert.ToInt32(field_map["height"].ToString());
                            int font_size = Convert.ToInt32(field_map["font_size"].ToString());
                            int top = (-height / 2) - (3 * font_size / 2);
                            HtmlAttribute style_attr = htmlDoc.CreateAttribute("style", "position:relative;top:" + top.ToString() + "px;");
                            p_node.Attributes.Append(style_attr);
                            new_node.AppendChild(p_node);
                            break;
                        case "image_button": //"<div title=\"MobiFlex ImageButton\"  style=\"{3}\" id=\"{0}\"  submit=\"{2}\"><img src=\"{1}\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex ImageButton";
                            string image_button_url = field_map["image_source"].ToString();
                            if (!field_map.ContainsKey("width")) //the xml does not have the width and height so use the width and height of the actual image
                            {
                                Size size = util.GetImageSize(image_button_url);
                                if (size != null)
                                {
                                    new_node.Attributes["style"].Value += "width:" + size.Width.ToString() + "px;height:" + size.Height.ToString() + "px;";
                                }
                            }
                            AddImageNode(htmlDoc, new_node, image_button_url);

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string image_button_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText.Replace(":", "%3A"));
                                    }
                                    image_button_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    image_button_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (image_button_submit.StartsWith("post"))
                                    {
                                        if (image_button_submit.Length >= 19)
                                           // image_button_submit = image_button_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                            image_button_submit = image_button_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (image_button_submit.Contains("next_page:"))
                                        image_button_submit = image_button_submit.Replace("next_page:", "next_page:page~");
                                    else if (image_button_submit.Contains("call:"))
                                        image_button_submit = image_button_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                image_button_submit += "compute:" + decode + ";";
                              }

                            HtmlAttribute image_button_submit_attr = htmlDoc.CreateAttribute("submit", image_button_submit);
                            new_node.Attributes.Append(image_button_submit_attr);
                            break;
                        case "picker": //"<div title=\"MobiFlex Picker\" style=\"position:absolute;z-index:{3};top:44px;left:0px;width:320px; height:216px;background-image:url('images/editor_images/datepicker.jpg');background-repeat:no-repeat\" id=\"{0}\"  type=\"{1}\" options=\"\"  />"
                            title_attr.Value = "MobiFlex Picker";
                            string picker_type = field_map["picker_type"].ToString();
                            if ((State["SelectedAppType"].ToString() == Constants.WEB_APP_TYPE || State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE) &&
                                picker_type != "date" &&
                                picker_type != "time" &&
                                picker_type != "1_section")
                            {
                                picker_type = "1_section";
                            }
                            HtmlAttribute picker_type_attr = htmlDoc.CreateAttribute("type", picker_type);
                            new_node.Attributes.Append(picker_type_attr);
                            if ((State["SelectedDeviceType"] != null && State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE) ||
                                (State["SelectedAppType"].ToString() == Constants.WEB_APP_TYPE || State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE))
                            {
                                switch (picker_type)
                                {
                                    case "date":
                                    case "time":
                                    case "1_section":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/spinner.jpg');background-repeat:no-repeat;";
                                        new_node.Attributes["style"].Value = new_node.Attributes["style"].Value.Replace("height:216px", "height:40px");
                                        break;
                                    case "2_sections":
                                    case "3_sections":
                                    case "4_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/2section_spinner.jpg');background-repeat:no-repeat;";
                                        break;
                                }
                            }
                            else
                            {
                                switch (picker_type)
                                {
                                    case "date":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/datepicker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "time":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/time_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "1_section":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/1section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "2_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/2section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "3_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/3section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "4_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/4section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                }
                            }
                            StringBuilder name_list = new StringBuilder();

                            if (picker_type.Contains("section"))
                            {
                                XmlNodeList picker_fields = field.SelectNodes("picker_fields/picker_field");
                                StringBuilder option_list = new StringBuilder();
                                bool isFirst = true;
                                foreach (XmlNode picker_field in picker_fields)
                                {
                                    XmlNode name_node = picker_field.SelectSingleNode("name");
                                    if (isFirst)
                                        isFirst = false;
                                    else
                                    {
                                        name_list.Append(",");
                                        option_list.Append("|");
                                    }
                                    name_list.Append(name_node.InnerText);
                                    XmlNode options_node = picker_field.SelectSingleNode("options");
                                    if (options_node != null)
                                        option_list.Append(options_node.InnerText);
                                    if ((State["SelectedAppType"].ToString() == Constants.WEB_APP_TYPE) || State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE )
                                        break;
                                }

                                HtmlAttribute picker_options = htmlDoc.CreateAttribute("options", EncodeStudioHtml(UnescapeXml(option_list.ToString())));
                                new_node.Attributes.Append(picker_options);

                                picker_type_attr.Value += ":" + name_list.ToString();
                            }
                            break;
                        case "text_area": //"position:absolute;z-index:{0};top:44px;left:10px;width:250px;height:300px;font-family:Verdana;font-size:16px;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;padding:5px;background-image:url('images/editor_images/text_area.png');background-repeat:no-repeat;background-size:100% 100%;overflow:hidden"
                            title_attr.Value = "MobiFlex TextArea";
                            new_node.Attributes["style"].Value += "background-image:url('images/editor_images/text_area.png');background-repeat:no-repeat;background-size:100% 100%;overflow:hidden;";
                            if (field_map.ContainsKey("text"))
                            {
                                HtmlAttribute text_attr = htmlDoc.CreateAttribute("text", EncodeStudioHtml(UnescapeXml(field_map["text"].ToString())));
                                new_node.Attributes.Append(text_attr);
                                new_node.InnerHtml = "<div style=\"padding:5px\">" + field_map["text"].ToString().Replace(@"\n", "<br/>") + "</div>";
                            }
                            string edit_type = "non_editable";
                            if (field_map.ContainsKey("edit_type"))
                            {
                                edit_type = field_map["edit_type"].ToString();
                            }
                            HtmlAttribute edit_type_attr = htmlDoc.CreateAttribute("type", edit_type);
                            new_node.Attributes.Append(edit_type_attr);
                            break;
                        case "switch": //"<div title=\"MobiFlex Switch\" id=\"{0}\" style=\"{4}\" type=\"{1}\" value=\"{2}\" submit=\"{3}\" ><img src=\"" + image_url + "\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Switch";
                            string switch_value = field_map["default_value"].ToString();
                            switch (switch_value)
                            {
                                case "on":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_on.png");
                                     break;
                                case "off":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_off.png");
                                    break;
                                case "yes":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_yes.png");
                                    break;
                                case "no":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_no.png");
                                    break;
                                case "true":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_true.png");
                                    break;
                                case "false":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_false.png");
                                    break;
                            }

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string switch_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText);
                                    }
                                    switch_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    switch_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (switch_submit.StartsWith("post"))
                                    {
                                        if (switch_submit.Length >= 19)
                                            //switch_submit = switch_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                             switch_submit = switch_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (switch_submit.Contains("next_page:"))
                                        switch_submit = switch_submit.Replace("next_page:", "next_page:page~");
                                    else if (switch_submit.Contains("call:"))
                                        switch_submit = switch_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                switch_submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute switch_type_attr = null;
                            if (field_map["type"] != null)
                                switch_type_attr = htmlDoc.CreateAttribute("type", field_map["type"].ToString());

                            else
                                switch_type_attr = htmlDoc.CreateAttribute("type", "on_off");

                            new_node.Attributes.Append(switch_type_attr);

                            HtmlAttribute value_attr = htmlDoc.CreateAttribute("value", field_map["default_value"].ToString());
                            new_node.Attributes.Append(value_attr);

                            HtmlAttribute switch_submit_attr = htmlDoc.CreateAttribute("submit", switch_submit);
                            new_node.Attributes.Append(switch_submit_attr);
                            break;
                        case "checkbox": //"<div title=\"MobiFlex Switch\" id=\"{0}\" style=\"{4}\" type=\"{1}\" value=\"{2}\" submit=\"{3}\" ><img src=\"" + image_url + "\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex CheckBox";
                            string checkbox_value = field_map["default_value"].ToString();
                            switch (checkbox_value)
                            {
                                case "checked":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/checkbox_on.png");
                                    break;
                                case "unchecked":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/checkbox_off.png");
                                    break;
                            }

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string checkbox_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText);
                                    }
                                    checkbox_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    checkbox_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (checkbox_submit.StartsWith("post"))
                                    {
                                        if (checkbox_submit.Length >= 19)
                                            //checkbox_submit = checkbox_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                            checkbox_submit = checkbox_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (checkbox_submit.Contains("next_page:"))
                                        checkbox_submit = checkbox_submit.Replace("next_page:", "next_page:page~");
                                    else if (checkbox_submit.Contains("call:"))
                                        checkbox_submit = checkbox_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                checkbox_submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute checkbox_value_attr = htmlDoc.CreateAttribute("value", field_map["default_value"].ToString());
                            new_node.Attributes.Append(checkbox_value_attr);

                            HtmlAttribute checkbox_submit_attr = htmlDoc.CreateAttribute("submit", checkbox_submit);
                            new_node.Attributes.Append(checkbox_submit_attr);
                            break;
                        case "slider": //"<div title=\"MobiFlex Slider\" id=\"{0}\" value=\"{2}\" style=\"z-index:{3};top:160px;left:10px;height:57px;width:283px;\" type=\"{1}\" ><img src=\"images/editor_images/horizontal_slider.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Slider";
                            string slider_type = field_map["type"].ToString();
                            HtmlAttribute slider_type_attr = htmlDoc.CreateAttribute("type", slider_type);
                            new_node.Attributes.Append(slider_type_attr);
                            switch (slider_type)
                            {
                                case "horizontal":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/horizontal_slider.png");
                                    break;
                                case "vertical":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/vertical_slider.png");
                                    break;
                            }
                            string min_value = field_map["min_value"].ToString();
                            string max_value = field_map["max_value"].ToString();
                            HtmlAttribute slider_value_attr = htmlDoc.CreateAttribute("value", min_value + ":" + max_value);
                            new_node.Attributes.Append(slider_value_attr);
                            break;
                        case "table": //"<div title=\"MobiFlex Table\" id=\"{0}\" name=\"{1}\" alt=\"MobiFlex Table\"  style=\"position:absolute;z-index:{5};top:44px;left:0px;height:416px;width:320px;background-image:url('images/editor_images/largetableview1textfield.jpg');background-repeat:no-repeat\"  fields=\"{2}\" options=\"{4}\" submit=\"{3}\" />"
                            title_attr.Value = "MobiFlex Table";
                            string display_name = field_map["id"].ToString();
                            if (field_map["display_name"] != null)
                            {
                                display_name = field_map["display_name"].ToString();
                            }
                            HtmlAttribute table_display_name_attr = htmlDoc.CreateAttribute("name", display_name);
                            new_node.Attributes.Append(table_display_name_attr);

                            string table_type = field_map["table_type"].ToString();
                            if (table_type.Contains("image1text") || table_type.Contains("imagetext") || table_type.Contains("image1texthidden"))
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView1Image1textField.jpg');background-repeat:no-repeat;";
                            else if (table_type.Contains("image2texts") || table_type.Contains("image2textshidden") )
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView1Image2TextFields.jpg');background-repeat:no-repeat;";
                            else if (table_type.Contains("1text") || table_type.Contains("1texthidden"))
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView1TextField.jpg');background-repeat:no-repeat;";
                            else if (table_type.Contains("2texts") || table_type.Contains("2textshidden"))
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView2TextFields.jpg');background-repeat:no-repeat;";

                            XmlNodeList table_fields = field.SelectNodes("table_fields/table_field");
                            StringBuilder type_list = new StringBuilder();
                            StringBuilder field_name_list = new StringBuilder();
                            StringBuilder table_option_list = new StringBuilder();
                           bool is_first_field = true;
                            foreach (XmlNode table_field in table_fields)
                            {
                                if (is_first_field)
                                    is_first_field = false;
                                else
                                {
                                    field_name_list.Append(",");
                                    type_list.Append( ",");
                                }
                                XmlNode field_name_node = table_field.SelectSingleNode("name");
                                field_name_list.Append(field_name_node.InnerText );
                                XmlNode type_node = table_field.SelectSingleNode("type");
                                type_list.Append(type_node.InnerText );
                                XmlNode options_node = table_field.SelectSingleNode("options");
                                if (options_node != null)
                                    table_option_list.Append(options_node.InnerText + "|");
                            }
                            if (table_option_list.Length > 0)
                                table_option_list.Remove(table_option_list.Length - 1, 1);

                            string fields = table_type + "|" + type_list.ToString() + ":" + field_name_list.ToString();
                            HtmlAttribute fields_attr = htmlDoc.CreateAttribute("fields", fields);
                            new_node.Attributes.Append(fields_attr);

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string table_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText);
                                    }
                                    table_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    table_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (table_submit.StartsWith("post"))
                                    {
                                        if (table_submit.Length >= 19)
                                           // table_submit = table_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                             table_submit = table_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (table_submit.Contains("next_page:"))
                                        table_submit = table_submit.Replace("next_page:", "next_page:page~");
                                    else if (table_submit.Contains("call:"))
                                        table_submit = table_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                table_submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute table_submit_attr = htmlDoc.CreateAttribute("submit", table_submit);
                            new_node.Attributes.Append(table_submit_attr);
                            if (table_option_list.Length > 0)
                            {
                                HtmlAttribute table_options = htmlDoc.CreateAttribute("options", EncodeStudioHtml(UnescapeXml(table_option_list.ToString())));
                                new_node.Attributes.Append(table_options);
                            }
                            break;
                        case "alert": //"<div title=\"MobiFlex Alert\" id=\"{0}\" style=\"z-index:{1};top:410px;left:270px;height:50px;width:50px;\"  ><img src=\"images/editor_images/alert.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Alert";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/alert.png");
                            break;
                        case "hidden_field": //"<div title=\"MobiFlex HiddenField\" id=\"{0}\" value=\"{1}\" style=\"position:absolute;z-index:{2};top:410px;left:0px;height:30px;width:30px;\"  ><img src=\"images/editor_images/hidden_field.png\" style=\"height:100%;width:100%;\"
                            title_attr.Value = "MobiFlex HiddenField";
                            if (!field_map.ContainsKey("value"))
                            {
                                HtmlAttribute hidden_value_attr = htmlDoc.CreateAttribute("value", "");
                                new_node.Attributes.Append(hidden_value_attr);
                            }
                            AddImageNode(htmlDoc, new_node, "images/editor_images/hidden_field.png");
                            break;
                        case "gps": //"<div title=\"MobiFlex GPS\" id=\"GPS\" alt=\"{0}\" style=\"z-index:{1};top:160px;left:10px;height:58px;width:56px;\"  ><img src=\"images/editor_images/gps.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex GPS";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/gps.png");
                            string latitude = field_map["latitude"].ToString();
                            string longitude = field_map["longitude"].ToString();
                            HtmlAttribute gps_attr = htmlDoc.CreateAttribute("alt", latitude + ";" + longitude);
                            new_node.Attributes.Append(gps_attr);
                            break;
                        case "map": //"<div title=\"MobiFlex Map\" alt=\"MobiFlex Map\" id=\"{0}\" style=\"position:absolute;z-index:{2};top:44px;left:0px;height:416px;width:320px;background-image:url('images/editor_images/map.jpg');background-repeat:no-repeat\"  url=\"{1}\" />"
                            title_attr.Value = "MobiFlex Map";
                            new_node.Attributes["style"].Value += "background-image:url('images/editor_images/map.jpg');background-repeat:no-repeat;";
                            break;
                        case "photo": //"<div title=\"MobiFlex Photo\" id=\"{0}\" compression=\"{1}\" icon_field=\"{2}\" style=\"z-index:{3};top:160px;left:10px;height:48px;width:48px;\"  ><img src=\"images/editor_images/picture_taker.gif\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Photo";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/picture_taker.gif");
                            break;
                        case "audio_recorder": //"<div title=\"MobiFlex AudioRecorder\" id=\"{0}\" style=\"z-index:{1};top:160px;left:10px;height:84px;width:198px;\"  ><img src=\"images/editor_images/audio_recorder.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex AudioRecorder";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/audio_recorder.png");
                            break;
                        case "speech_recognition": // "<div title=\"MobiFlex SpeechRecognition\" alt=\"MobiFlex Speech Recognition\" id=\"{0}\" style=\"z-index:{2};top:48px;left:0px;height:412px;width:320px;\" choice_title=\"{1}\"  ><img src=\"images/editor_images/speech_recognition.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex SpeechRecognition";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/speech_recognition.png");
                            break;

                    }
                    new_node.Attributes.Append(title_attr);

                    root.AppendChild(new_node);
                }
                catch (Exception ex)
                {
                    util.LogError(State, ex);
                    throw new Exception(ex.Message + ": " + ex.StackTrace);
                }
            }
            try
            {
                return htmlDoc.DocumentNode.WriteContentTo();
            }
            catch //work around bug in 3rd party package
            {
                return "";
            }
        }
        catch (Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            throw new Exception(ex.Message + ": " + ex.StackTrace);
        }
    }
        /// <summary>
        /// Loads the HTML.
        /// </summary>
        /// <param name="inputUri">The input URI.</param>
        /// <returns>
        /// The loaded HTML from the specified input URI.
        /// </returns>
        public Task<string> LoadHtml(string inputUri)
        {
            return new Task<string>(
                () =>
                {
                    if (string.IsNullOrWhiteSpace(inputUri))
                    {
                        return "<html><head></head><body></body></html>";
                    }

                    var htmlDocument = new HtmlDocument();
                    var request = (HttpWebRequest)WebRequest.Create(inputUri);
                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            using (var receiveStream = response.GetResponseStream())
                            {
                                StreamReader readStream = null;

                                if (response.CharacterSet == null)
                                {
                                    readStream = new StreamReader(receiveStream);
                                }
                                else
                                {
                                    readStream = new StreamReader(
                                        receiveStream, Encoding.GetEncoding(response.CharacterSet));
                                }

                                htmlDocument.Load(readStream.BaseStream, false);
                                readStream.Close();
                            }
                        }
                    }

                    if ((htmlDocument.DocumentNode == null) ||
                        string.IsNullOrWhiteSpace(htmlDocument.DocumentNode.InnerHtml))
                    {
                        return "<html><head></head><body><h1>Load error!</h1><br/><h3>Error without description or unknown.</h3></body></html>";
                    }

                    var noErrorScriptHtml =
                        "<script type=\"text/javascript\">function noError(){return true;} window.onerror=noError;</script>";

                    var headNode = htmlDocument.DocumentNode.SelectSingleNode("//head");

                    headNode.InsertBefore(
                        htmlDocument.CreateTextNode(noErrorScriptHtml),
                        headNode.FirstChild);

                    var bodyNode = htmlDocument.DocumentNode.SelectSingleNode("//body");

                    bodyNode.InsertBefore(
                        htmlDocument.CreateTextNode(noErrorScriptHtml),
                        bodyNode.FirstChild);

                    var htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"content\"]");

                    var nodesToRemove = new List<HtmlNode>();

                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"jp-post-flair\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"sidebar-after-singular\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"comments-template\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"footer\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"sidebar-primary\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@id=\"bit\"]"));
                    nodesToRemove.Add(htmlDocument.DocumentNode.SelectSingleNode("//div[@class=\"wpcnt\"]"));

                    foreach (var nodeToRemove in nodesToRemove.Where(node => (node != null)))
                    {
                        nodeToRemove.Remove();
                    }

                    var linkNodes = htmlDocument.DocumentNode.SelectNodes("//a");

                    foreach (var linkNode in linkNodes)
                    {
                        linkNode.SetAttributeValue("target", "_blank");
                    }

                    if (htmlNode != null)
                    {
                        htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class=\"entry-content\"]");

                        bodyNode.RemoveAllChildren();
                        bodyNode.AppendChild(htmlNode);
                    }

                    return htmlDocument.DocumentNode.InnerHtml;
                });
        }