本文整理汇总了C#中HtmlDocument.CreateElement方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlDocument.CreateElement方法的具体用法?C# HtmlDocument.CreateElement怎么用?C# HtmlDocument.CreateElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlDocument
的用法示例。
在下文中一共展示了HtmlDocument.CreateElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateElement
public void CreateElement()
{
var doc = new HtmlDocument();
var a = doc.CreateElement("a");
Assert.AreEqual("a", a.Name);
Assert.AreEqual(a.NodeType, HtmlNodeType.Element);
}
示例2: 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);
}
示例3: Test_Constructing_Node_With_Single_Attribute
public void Test_Constructing_Node_With_Single_Attribute()
{
var doc = new HtmlDocument();
var a = doc.CreateElement("a");
a.SetAttributeValue("href", "foo");
a.InnerHtml = "foo";
doc.DocumentNode.AppendChild(a);
Assert.AreEqual("<a href=\"foo\">foo</a>", doc.Save());
}
示例4: GetWebApp
//.........这里部分代码省略.........
break;
}
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)
示例5: GenerateSiteMap
/// <summary>
/// Generate Site Map based on Cache Result of the database.
/// </summary>
/// <param name="requestParam"></param>
/// <returns></returns>
public string GenerateSiteMap(string requestParam)
{
int DbNid = -1;
string RetVal = "false";
string DefaultLanguageCode = string.Empty;
DataRow[] drArray = null;
DataRow[] DataRows = null;
DataRow[] DataRowsInd = null;
string SiteMapName = string.Empty;
string SiteMapData = string.Empty;
string[] SiteMapDataArray = null;
string Query = string.Empty;
bool FirstSitemap = true;
ArrayList ALAreas = new ArrayList();
string SectorIndicators = string.Empty;
string BlockAreaNIds = string.Empty;
DbNid = int.Parse(requestParam);
DIConnection ObjDIConnection = null;
string SiteMapHtmlPagePath;
string FinalAreaNids = string.Empty;
HtmlDocument HtmDocument = null;
StringBuilder SbSiteMapSectors = new StringBuilder();
ObjDIConnection = Global.GetDbConnection(DbNid);
DataTable DTAreas = null;
DataTable DTBlockAreasParent = null;
DataTable DTBlockAreas = null;
DataTable DTCacheData = null;//ObjDIConnection.ExecuteDataTable("SP_GET_SITEMAP_DATA", CommandType.StoredProcedure, new List<DbParameter>());
//Get Default Indicators and Areas
//DataTable DefaultIndicators = Global.GetDefaultIndicator(Global.GetDefaultDbNId());
DefaultLanguageCode = Global.GetDefaultLanguageCode();
DataTable DefaultIndicators = GetDefaultIndicators(DefaultLanguageCode, Query, ObjDIConnection);
DataTable DefaultAreas = GetDefaultAreas(ref DefaultLanguageCode, ref Query, ALAreas, ref BlockAreaNIds, ObjDIConnection, ref DTAreas, ref DTBlockAreasParent, ref DTBlockAreas);
DataTable DTIndArea = MakeIndAreaTable(DefaultIndicators, DefaultAreas);
Query = "SELECT DISTINCT IC.IC_Name,IC.IC_NId,IUS.Indicator_NId from ut_indicator_classifications_" + DefaultLanguageCode + " IC,ut_indicator_unit_subgroup IUS,ut_ic_ius ICIUS WHERE IC.IC_NId = ICIUS.IC_NId AND ICIUS.IUSNId = IUS.IUSNId AND IC.IC_Type='SC' AND IC.IC_Parent_NId ='-1'";
DataTable DTIndicatorSector = ObjDIConnection.ExecuteDataTable(Query);
if (DTIndicatorSector.Rows.Count == 1)
{
Query = "SELECT DISTINCT IC.IC_Name,IC.IC_NId,IUS.Indicator_NId from ut_indicator_classifications_" + DefaultLanguageCode + " IC,ut_indicator_unit_subgroup IUS,ut_ic_ius ICIUS WHERE IC.IC_NId = ICIUS.IC_NId AND ICIUS.IUSNId = IUS.IUSNId AND IC.IC_Type='SC' AND IC.IC_Parent_NId IN(SELECT IC_NId from ut_indicator_classifications_en where IC_Parent_NId='-1') ";
DTIndicatorSector = ObjDIConnection.ExecuteDataTable(Query);
}
//Get Sectors List.
DataTable DTSector = DTIndicatorSector.DefaultView.ToTable(true, "IC_NId", "IC_Name");
FileInfo ScriptFile = new FileInfo(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, Global.DropNCreateSitemapURLTable));
string DbScripts = ScriptFile.OpenText().ReadToEnd();
// Execute script file to check and create database schema
ObjDIConnection.ExecuteNonQuery(DbScripts);
XmlDocument XMLPDoc = new XmlDocument();
XmlNode declaration = XMLPDoc.CreateNode(XmlNodeType.XmlDeclaration, null, null);
XMLPDoc.AppendChild(declaration);
XmlElement URLSet = XMLPDoc.CreateElement("sitemapindex");
XMLPDoc.AppendChild(URLSet);
URLSet.SetAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
URLSet.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
URLSet.SetAttribute("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd");
#region "-- SiteMapHtml"
// Create Html Document object
HtmDocument = new HtmlDocument();
// Get Site Map Html File Path
SiteMapHtmlPagePath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, Constants.FileName.SitemapHtmlPage);
if (File.Exists(SiteMapHtmlPagePath))
{
File.Delete(SiteMapHtmlPagePath);
}
// Load Html Document
HtmDocument.LoadHtml("");
// Create Main Div For Data
// Crate Main Div for Data
HtmlNode DivMain;
HtmlNode DivSectorContainer;
DivMain = HtmDocument.CreateElement("div");
DivMain.SetAttributeValue("id", "DivMain_Container");
// DivMain.ChildNodes.Append(.Add("innerHtml", "Data");
DivSectorContainer = HtmDocument.CreateElement("div");
DivSectorContainer.SetAttributeValue("id", "DivSectorContainer");
DivSectorContainer.SetAttributeValue("class", "sitemap");
#endregion
StringBuilder SbSectorInnerLinks = new StringBuilder();
try
{
//Add IUS data Links
foreach (DataRow dr in DTSector.Rows)
{
//.........这里部分代码省略.........
示例6: 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%");
//.........这里部分代码省略.........