本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.CreateAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.CreateAttribute方法的具体用法?C# HtmlDocument.CreateAttribute怎么用?C# HtmlDocument.CreateAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.CreateAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddImageNode
public void AddImageNode(HtmlDocument htmlDoc,HtmlNode new_node,string image_source)
{
//<img src=\"{1}\" style=\"height:100%;width:100%;\"/>
HtmlNode image_node = htmlDoc.CreateElement("img");
HtmlAttribute src_attr = htmlDoc.CreateAttribute("src", image_source);
image_node.Attributes.Append(src_attr);
HtmlAttribute style_attr = htmlDoc.CreateAttribute("style", "height:100%;width:100%;");
image_node.Attributes.Append(style_attr);
new_node.AppendChild(image_node);
}
示例2: GetFull
public static string GetFull(string html, bool removeAsccut = true)
{
html = html ?? string.Empty;
try
{
var doc = new HtmlDocument();
doc.LoadHtml(string.Format("<html>{0}</html>", HTMLTags.Replace(html, string.Empty)));
if (removeAsccut)
{
var nodes = doc.DocumentNode.SelectNodes("//div[translate(@class,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='asccut']");
if (nodes != null)
{
foreach (var node in nodes)
{
node.Attributes.Remove("class");
var styleAttr = doc.CreateAttribute("style");
styleAttr.Value = "display:inline;";
node.Attributes.Append(styleAttr);
}
}
}
ProcessCustomTags(doc);
return HTMLTags.Replace(doc.DocumentNode.InnerHtml, string.Empty);
}
catch (Exception e)
{
return e.Message + "<br/> Please contact us: <a href='mailto:[email protected]'>[email protected]</a>";
}
}
示例3: GetFull
public static string GetFull(string html, Guid productID)
{
html = html ?? string.Empty;
var doc = new HtmlDocument();
doc.LoadHtml(string.Format("<html>{0}</html>", htmlTags.Replace(html, string.Empty)));
var nodes = doc.DocumentNode.SelectNodes("//div[translate(@class,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='asccut']");
if (nodes != null)
{
foreach (var node in nodes)
{
node.Attributes.Remove("class");
var styleAttr = doc.CreateAttribute("style");
styleAttr.Value = "display:inline;";
node.Attributes.Append(styleAttr);
}
}
ProcessCustomTags(doc, productID);
return htmlTags.Replace(doc.DocumentNode.InnerHtml, string.Empty);
}
示例4: ProcessAscUserTag
private static void ProcessAscUserTag(HtmlDocument doc, Guid productID)
{
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@__ascuser]");
HtmlAttribute styleAttr;
if (nodes == null || nodes.Count == 0)
return;
foreach (HtmlNode node in nodes)
{
Guid userId = new Guid(node.Attributes["__ascuser"].Value);
node.Attributes.RemoveAll();
styleAttr = doc.CreateAttribute("style");
styleAttr.Value = "display:inline;";
node.Attributes.Append(styleAttr);
node.InnerHtml = CoreContext.UserManager.GetUsers(userId).RenderProfileLinkBase(productID);
}
}
示例5: ProcessZoomImages
private static void ProcessZoomImages(HtmlDocument doc, Guid productID)
{
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//img[@_zoom]");
HtmlNode hrefNode;
HtmlAttribute borderAttribute, hrefAttribute, srcAttribute, zoomAttribute;
string imgSrc = string.Empty;
if (nodes == null)
return;
foreach (HtmlNode node in nodes)
{
srcAttribute = node.Attributes["src"];
if (srcAttribute == null || string.IsNullOrEmpty(srcAttribute.Value))
continue;
zoomAttribute = node.Attributes["_zoom"];
if (zoomAttribute == null || string.IsNullOrEmpty(zoomAttribute.Value))
continue;
borderAttribute = node.Attributes["border"];
if (borderAttribute == null)
{
borderAttribute = doc.CreateAttribute("border");
node.Attributes.Append(borderAttribute);
}
borderAttribute.Value = "0";
imgSrc = srcAttribute.Value;
if (!rxNumeric.IsMatch(zoomAttribute.Value))
{
imgSrc = zoomAttribute.Value;
}
if (node.ParentNode != null)
{
hrefNode = doc.CreateElement("a");
hrefAttribute = doc.CreateAttribute("href");
hrefAttribute.Value = imgSrc;
hrefNode.Attributes.Append(hrefAttribute);
hrefAttribute = doc.CreateAttribute("class");
hrefAttribute.Value = "fancyzoom";
hrefNode.Attributes.Append(hrefAttribute);
/*
hrefAttribute = doc.CreateAttribute("onclick");
hrefAttribute.Value = string.Format(@"javascript:if(typeof(popimgFckup) == 'function')popimgFckup('{0}');", srcAttribute.Value);
hrefNode.Attributes.Append(hrefAttribute);*/
node.ParentNode.ReplaceChild(hrefNode, node);
hrefNode.AppendChild(node);
}
}
}
示例6: ProcessZoomImages
private static void ProcessZoomImages(HtmlDocument doc)
{
var nodes = doc.DocumentNode.SelectNodes("//img[@_zoom]");
if (nodes == null) return;
foreach (var node in nodes)
{
if (node.ParentNode != null && (node.ParentNode.Name ?? "").ToLower() == "a") continue;
var srcAttribute = node.Attributes["src"];
if (srcAttribute == null || string.IsNullOrEmpty(srcAttribute.Value)) continue;
var zoomAttribute = node.Attributes["_zoom"];
if (zoomAttribute == null || string.IsNullOrEmpty(zoomAttribute.Value)) continue;
var borderAttribute = node.Attributes["border"];
if (borderAttribute == null)
{
borderAttribute = doc.CreateAttribute("border");
node.Attributes.Append(borderAttribute);
}
borderAttribute.Value = "0";
var imgSrc = srcAttribute.Value;
if (!RxNumeric.IsMatch(zoomAttribute.Value))
{
imgSrc = zoomAttribute.Value;
}
if (node.ParentNode != null)
{
var hrefNode = doc.CreateElement("a");
var hrefAttribute = doc.CreateAttribute("href");
hrefAttribute.Value = imgSrc;
hrefNode.Attributes.Append(hrefAttribute);
hrefAttribute = doc.CreateAttribute("class");
hrefAttribute.Value = "screenzoom";
hrefNode.Attributes.Append(hrefAttribute);
string title = null;
var titleAttribute = node.Attributes["title"];
if (titleAttribute != null)
{
title = titleAttribute.Value;
}
else
{
var altAttribute = node.Attributes["alt"];
if (altAttribute != null)
{
title = altAttribute.Value;
}
}
if (!string.IsNullOrEmpty(title))
{
hrefAttribute = doc.CreateAttribute("title");
hrefAttribute.Value = title;
hrefNode.Attributes.Append(hrefAttribute);
}
node.ParentNode.ReplaceChild(hrefNode, node);
hrefNode.AppendChild(node);
}
}
}
示例7: ParseHelpCenterHtml
private static List<HelpCenterItem> ParseHelpCenterHtml(string html, string helpLinkBlock)
{
var helpCenterItems = new List<HelpCenterItem>();
if (string.IsNullOrEmpty(html)) return helpCenterItems;
var doc = new HtmlDocument();
doc.LoadHtml(html);
var urlHelp = CommonLinkUtility.GetHelpLink(false);
var mainContent = doc.DocumentNode.SelectSingleNode("//div[@class='MainHelpCenter GettingStarted']");
if (mainContent == null) return helpCenterItems;
var blocks = (mainContent.SelectNodes(".//div[@class='gs_content']"))
.Where(r => r.Attributes["id"] != null)
.Select(x => x.Attributes["id"].Value).ToList();
foreach (var block in mainContent.SelectNodes(".//div[@class='gs_content']"))
{
var hrefs = block.SelectNodes(".//a[@href]")
.Where(r =>
{
var value = r.Attributes["href"].Value;
return r.Attributes["href"] != null
&& !string.IsNullOrEmpty(value)
&& !value.StartsWith("mailto:")
&& !value.StartsWith("http");
});
foreach (var href in hrefs)
{
var value = href.Attributes["href"].Value;
if (value.IndexOf("#", StringComparison.Ordinal) != 0 && value.Length > 1)
{
href.Attributes["href"].Value = urlHelp + value.Substring(1);
href.SetAttributeValue("target", "_blank");
}
else
{
if (!blocks.Contains(value.Substring(1))) continue;
href.Attributes["href"].Value = helpLinkBlock + blocks.IndexOf(value.Substring(1)).ToString(CultureInfo.InvariantCulture);
}
}
var images = block.SelectNodes(".//img");
if (images != null)
{
foreach (var img in images.Where(img => img.Attributes["src"] != null))
{
img.Attributes["src"].Value = GetInternalLink(urlHelp + img.Attributes["src"].Value);
}
foreach (var screenPhoto in images.Where(img =>
img.Attributes["class"] != null && img.Attributes["class"].Value.Contains("screenphoto")
&& img.Attributes["target"] != null && img.ParentNode != null))
{
var bigphotoScreenId = screenPhoto.Attributes["target"].Value;
var bigphotoScreen = images.FirstOrDefault(img =>
img.Attributes["id"] != null && img.Attributes["id"].Value == bigphotoScreenId
&& img.Attributes["class"] != null && img.Attributes["class"].Value.Contains("bigphoto_screen")
&& img.Attributes["src"] != null);
if (bigphotoScreen == null) continue;
var hrefNode = doc.CreateElement("a");
var hrefAttribute = doc.CreateAttribute("href");
hrefAttribute.Value = bigphotoScreen.Attributes["src"].Value;
hrefNode.Attributes.Append(hrefAttribute);
hrefAttribute = doc.CreateAttribute("class");
hrefAttribute.Value = "screenzoom";
hrefNode.Attributes.Append(hrefAttribute);
hrefAttribute = doc.CreateAttribute("rel");
hrefAttribute.Value = "imageHelpCenter";
hrefNode.Attributes.Append(hrefAttribute);
screenPhoto.ParentNode.ReplaceChild(hrefNode, screenPhoto);
hrefNode.AppendChild(screenPhoto);
}
}
var titles = block.SelectSingleNode(".//h2");
var contents = block.SelectSingleNode(".//div[@class='PortalHelp']");
if (titles != null && contents != null)
{
helpCenterItems.Add(new HelpCenterItem { Title = titles.InnerText, Content = contents.InnerHtml });
}
}
return helpCenterItems;
}
示例8: ProcessZoomImages
private static void ProcessZoomImages(HtmlDocument doc)
{
var nodes = doc.DocumentNode.SelectNodes("//img[@_zoom]");
if (nodes == null) return;
foreach (var node in nodes)
{
var srcAttribute = node.Attributes["src"];
if (srcAttribute == null || string.IsNullOrEmpty(srcAttribute.Value)) continue;
var zoomAttribute = node.Attributes["_zoom"];
if (zoomAttribute == null || string.IsNullOrEmpty(zoomAttribute.Value)) continue;
var borderAttribute = node.Attributes["border"];
if (borderAttribute == null)
{
borderAttribute = doc.CreateAttribute("border");
node.Attributes.Append(borderAttribute);
}
borderAttribute.Value = "0";
var imgSrc = srcAttribute.Value;
if (!RxNumeric.IsMatch(zoomAttribute.Value))
{
imgSrc = zoomAttribute.Value;
}
if (node.ParentNode != null)
{
var hrefNode = doc.CreateElement("a");
var hrefAttribute = doc.CreateAttribute("href");
hrefAttribute.Value = imgSrc;
hrefNode.Attributes.Append(hrefAttribute);
hrefAttribute = doc.CreateAttribute("class");
hrefAttribute.Value = "screenzoom";
hrefNode.Attributes.Append(hrefAttribute);
/*
hrefAttribute = doc.CreateAttribute("onclick");
hrefAttribute.Value = string.Format(@"javascript:if(typeof(popimgFckup) == 'function')popimgFckup('{0}');", srcAttribute.Value);
hrefNode.Attributes.Append(hrefAttribute);*/
node.ParentNode.ReplaceChild(hrefNode, node);
hrefNode.AppendChild(node);
}
}
}
示例9: SetCommonHtmlAttributes
public void SetCommonHtmlAttributes(HtmlDocument htmlDoc, HtmlNode field_node, Hashtable field_map, double x_size_factor , double y_size_factor , string field_type)
{
XmlUtil x_util = new XmlUtil();
//init style
HtmlAttribute style = htmlDoc.CreateAttribute("style", "position:absolute;");
field_node.Attributes.Append(style);
HtmlAttribute icon_field = null;
int MinTextFieldHeight = 30;
int MinButtonHeight = 30;
//set default z-index
if (!field_map.ContainsKey("z_index"))
field_map["z_index"] = "50";
if (field_type == "text_field" || field_type == "text_area" || field_type == "label" || field_type == "button")
{
if (!field_map.ContainsKey("font_style"))
field_map["font_style"] = "normal";
if (!field_map.ContainsKey("font_weight"))
field_map["font_weight"] = "normal";
if (!field_map.ContainsKey("text_decoration"))
field_map["text_decoration"] = "none";
/*if (field_type == "text_area")
{
//add 20 px to height and width of top node and then subtract 20 px for subnode of textarea later in SetTextHtmlAttributes
field_map["height"] = Convert.ToInt32(field_map["height"].ToString()) + 20;
field_map["width"] = Convert.ToInt32(field_map["width"].ToString()) + 20;
}*/
}
//process buttons specially
if (field_type == "button")
{
int height = Convert.ToInt32(field_map["height"].ToString());
// int width = Convert.ToInt32(field_map["width"].ToString());
//field_map["width"] = (width + 20).ToString();
int top = Convert.ToInt32(field_map["top"].ToString());
//int left = Convert.ToInt32(field_map["left"].ToString());
//field_map["left"] = (left - 10).ToString();
if (height < MinButtonHeight)
{
field_map["height"] = MinButtonHeight.ToString();
top -= (MinButtonHeight - height) / 2;
field_map["top"] = top.ToString();
}
}
else if (field_type == "text_field")
{
int height = Convert.ToInt32(field_map["height"].ToString());
int top = Convert.ToInt32(field_map["top"].ToString());
if (height < MinTextFieldHeight)
{
field_map["height"] = MinTextFieldHeight.ToString();
top -= (MinTextFieldHeight - height) / 2;
field_map["top"] = top.ToString();
}
}
foreach (string key in field_map.Keys)
{
switch (key)
{
case "icon_field":
if (field_node.Attributes["icon_field"] == null)
{
icon_field = htmlDoc.CreateAttribute("icon_field", "field:" + field_map[key].ToString() + ";");
field_node.Attributes.Append(icon_field);
}
else
field_node.Attributes["icon_field"].Value += "field:" + field_map[key].ToString() + ";";
break;
case "icon_width":
if (field_node.Attributes["icon_field"] == null)
{
icon_field = htmlDoc.CreateAttribute("icon_field", "width:" + field_map[key].ToString() + ";");
field_node.Attributes.Append(icon_field);
}
else
field_node.Attributes["icon_field"].Value += "width:" + field_map[key].ToString() + ";";
break;
case "icon_height":
if (field_node.Attributes["icon_field"] == null)
{
icon_field = htmlDoc.CreateAttribute("icon_field", "height:" + field_map[key].ToString() + ";");
field_node.Attributes.Append(icon_field);
}
else
field_node.Attributes["icon_field"].Value += "height:" + field_map[key].ToString() + ";";
break;
case "url":
case "alt":
case "title":
case "id":
case "class":
case "src":
HtmlAttribute attr = htmlDoc.CreateAttribute(key, field_map[key].ToString());
field_node.Attributes.Append(attr);
break;
case "value":
HtmlAttribute val_attr = htmlDoc.CreateAttribute(key, HttpUtility.HtmlAttributeEncode(x_util.UnescapeXml(field_map[key].ToString())));
field_node.Attributes.Append(val_attr);
break;
//.........这里部分代码省略.........
示例10: GetWebApp
//.........这里部分代码省略.........
}
if((bool)State["IsProduction"])
customInitScript.Append("\tvar is_production = true;\n");
else
customInitScript.Append("\tvar is_production = false;\n");
string device_type = x_util.GetAppDeviceType(State);
if (device_type == Constants.IPAD || device_type == Constants.ANDROID_TABLET)
customInitScript.Append("\tvar does_background_image_exist = false;\n");
else
customInitScript.Append("\tvar does_background_image_exist = true;\n");
if (DS.DoesAppUseGoogleSpreadsheets(State))
{
customInitScript.Append("\tvar doesAppUseGoogleSpreadsheets = true;\n");
customInitScript.Append("\tvar isGoogleDataLoaded = false;\n");
customInitScript.Append("google.load('gdata', '2.x');\n");
customInitScript.Append("google.setOnLoadCallback(onGoogleDataLoad);\n");
customInitScript.Append("function onGoogleDataLoad() {isGoogleDataLoaded=true;}\n");
}
else
{
customInitScript.Append("\tvar doesAppUseGoogleSpreadsheets = false;\n");
customInitScript.Append("\tvar isGoogleDataLoaded = false;\n");
}
customInitScript.Append("\tvar latitude;\n");
customInitScript.Append("\tvar longitude;\n");
//get app icon
HtmlNode head_node = root.SelectSingleNode("//head");
HtmlNode icon_node = htmlDoc.CreateElement("link");
icon_node.Attributes.Append(htmlDoc.CreateAttribute("rel", "apple-touch-icon"));
if (device_type == Constants.IPAD || device_type == Constants.ANDROID_TABLET)
{
if ((bool)State["IsProduction"] == false)
{
icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_icon_ipad.png"));
}
else
{
icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", util.GetApplicationIcon(State, application_id, "72")));
}
}
else
{
if ((bool)State["IsProduction"] == false)
{
icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_icon.jpg"));
}
else
{
icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", util.GetApplicationIcon(State, application_id, "57")));
}
}
head_node.AppendChild(icon_node);
if (device_type == Constants.IPAD || device_type == Constants.ANDROID_TABLET)
{
HtmlNode ipad_splash_node = htmlDoc.CreateElement("link");
ipad_splash_node.Attributes.Append(htmlDoc.CreateAttribute("rel", "apple-touch-startup-image"));
ipad_splash_node.Attributes.Append(htmlDoc.CreateAttribute("media", "screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)"));
if ((bool)State["IsProduction"] == false)
{
示例11: AddImageDimenssionsToHtml
/// <summary>
/// Add the dimenssions of images to the Html ensuring that the images has max width of 960 pixels
/// </summary>
/// <param name="htmlDoc"></param>
private void AddImageDimenssionsToHtml(HtmlDocument htmlDoc)
{
HtmlNodeCollection imgNodes = htmlDoc.DocumentNode.SelectNodes("//img[@src]");
if (imgNodes == null)
{
return;
}
foreach (HtmlNode imgNode in imgNodes)
{
Image img;
try
{
img = Image.FromFile(imgNode.Attributes["src"].Value);
}
catch (Exception)
{
Console.WriteLine("Error in AddImageDimenssionsToHtml: No image found at {0}", imgNode.Attributes["src"].Value);
continue;
}
HtmlAttribute heightAttr = htmlDoc.CreateAttribute("height");
HtmlAttribute widthAttr = htmlDoc.CreateAttribute("width");
if (img.Width > MaxWidth)
{
heightAttr.Value = ((img.Height * MaxWidth) / (img.Width)).ToString(CultureInfo.CurrentCulture);
widthAttr.Value = MaxWidth.ToString(CultureInfo.CurrentCulture);
}
else
{
heightAttr.Value = img.Height.ToString();
widthAttr.Value = img.Width.ToString();
}
img.Dispose();
imgNode.Attributes.Add(heightAttr);
imgNode.Attributes.Add(widthAttr);
}
}
示例12: ConvertMathMl
/// <summary>
/// Converts the MathML blocks to be readable by OneNote
/// </summary>
/// <param name="htmlDoc"></param>
private void ConvertMathMl(HtmlDocument htmlDoc)
{
HtmlNodeCollection mathNodes = htmlDoc.DocumentNode.SelectNodes("//math");
if (mathNodes == null)
{
return;
}
foreach (var mathNode in mathNodes.ToList())
{
mathNode.Attributes.RemoveAll();
HtmlAttribute mathMlNamespaceAttr = htmlDoc.CreateAttribute("xmlns:mml", MathMlNameSpace);
mathNode.Attributes.Add(mathMlNamespaceAttr);
foreach (var node in mathNode.DescendantsAndSelf())
{
node.Name = "mml:" + node.Name;
}
string newMathMlString = String.Format(MathMlOutline, mathNode.OuterHtml);
HtmlCommentNode newMathNode = htmlDoc.CreateComment(newMathMlString);
mathNode.ParentNode.ReplaceChild(newMathNode, mathNode);
}
}
示例13: MakeNode
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;
}
示例14: GetAppPage
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%");
//.........这里部分代码省略.........
示例15: SetCommonHtmlAttributes
public void SetCommonHtmlAttributes(HtmlDocument htmlDoc, HtmlNode new_node, Hashtable field_map,double y_factor,string field_type)
{
//init style
HtmlAttribute style = htmlDoc.CreateAttribute("style","position:absolute;");
new_node.Attributes.Append(style);
HtmlAttribute icon_field = null;
//set default z-index
if(!field_map.ContainsKey("z_index"))
field_map["z_index"] = "50";
if (field_type == "text_field" || field_type == "text_area" || field_type == "label" || field_type == "button")
{
if (!field_map.ContainsKey("font_style"))
field_map["font_style"] = "normal";
if (!field_map.ContainsKey("font_weight"))
field_map["font_weight"] = "normal";
if (!field_map.ContainsKey("text_decoration"))
field_map["text_decoration"] = "none";
}
foreach (string key in field_map.Keys)
{
switch (key)
{
case "icon_field":
if (new_node.Attributes["icon_field"] == null)
{
icon_field = htmlDoc.CreateAttribute("icon_field", "field:" + field_map[key].ToString() + ";");
new_node.Attributes.Append(icon_field);
}
else
new_node.Attributes["icon_field"].Value += "field:" + field_map[key].ToString() + ";";
break;
case "icon_width":
if (new_node.Attributes["icon_field"] == null)
{
icon_field = htmlDoc.CreateAttribute("icon_field", "width:" + field_map[key].ToString() + ";");
new_node.Attributes.Append(icon_field);
}
else
new_node.Attributes["icon_field"].Value += "width:" + field_map[key].ToString() + ";";
break;
case "icon_height":
if (new_node.Attributes["icon_field"] == null)
{
icon_field = htmlDoc.CreateAttribute("icon_field", "height:" + field_map[key].ToString() + ";");
new_node.Attributes.Append(icon_field);
}
else
new_node.Attributes["icon_field"].Value += "height:" + field_map[key].ToString() + ";";
break;
case "compression":
case "url":
case "alt":
case "title":
case "id":
case "class":
case "type":
case "src":
HtmlAttribute attr = htmlDoc.CreateAttribute(key, field_map[key].ToString());
new_node.Attributes.Append(attr);
break;
case "value":
HtmlAttribute val_attr = htmlDoc.CreateAttribute(key, EncodeStudioHtml(UnescapeXml(field_map[key].ToString())));
new_node.Attributes.Append(val_attr);
break;
case "top":
case "height":
if (y_factor == 1.0D)
new_node.Attributes["style"].Value += key + ":" + field_map[key].ToString() + "px;";
else
{
double y = Math.Round(Convert.ToDouble(field_map[key].ToString()) * y_factor);
new_node.Attributes["style"].Value += key + ":" + y.ToString() + "px;";
}
break;
case "left":
case "width":
case "font_size":
new_node.Attributes["style"].Value += key.Replace("_", "-") + ":" + field_map[key].ToString() + "px;";
break;
case "z_index":
case "font_family":
case "color":
case "font_style":
case "font_weight":
case "text_decoration":
case "background_color":
case "overflow":
new_node.Attributes["style"].Value += key.Replace("_","-") + ":" + field_map[key].ToString() + ";";
break;
}
}
}