模板文件($中间为占位符,后期会替换处理)(SubjectSimp.html)
<foreach>
<li>
<span class="pro-img"><a target="_blank" href="$Url$"><img src="$ThumbnailUrl$" alt="$ProductName$"></a></span>
<div class="pro-info">
<div class="pro-name">
<a href="$Url$">$ProductName$</a>
</div>
<div class="pro-price">
<span><i class="rmb">€</i>$RankPrice$</span><i>€$MarketPrice$</i>
<span>消费积分:<i>$PresentIntegral$</i></span>
</div>
</div>
</li>
</foreach>
处理文件(Common_SubjectProduct_Simple.cs)
string url = Globals.PhysicalPath(HiContext.Current.GetSkinPath() + "/" + this.SkinName);//获取目标文件地址
HtmlDocument htmlDocument = this.GetHtmlDocument(url);//打开目标文件
HtmlNode node2 = htmlDocument.DocumentNode.SelectSingleNode("//foreach");//获得目标文件的节点
string innerHtml = htmlDocument.DocumentNode.InnerHtml;//获得目标文件内容
if (node2 != null)
{
sb.AppendLine(innerHtml.Substring(0, innerHtml.IndexOf("<foreach>")));
foreach (DataRow row in tbProducts.Rows)
{
string defaultProductImage = SettingsManager.GetMasterSettings().DefaultProductImage;
if (!string.IsNullOrEmpty(row["ThumbnailUrl" + node.Attributes["ImageSize"].Value].ToNullString()))
{
defaultProductImage = row["ThumbnailUrl" + node.Attributes["ImageSize"].Value].ToString();
}
string str4 = Globals.ApplicationPath + defaultProductImage;
string newValue = Globals.GetSiteUrls().UrlData.FormatUrl("productDetails", new object[] { row["ProductId"] });
string str6 = row["ProductName"].ToString();
string str7 = string.Empty;
string str8 = Globals.FormatMoney(row["SalePrice"].ToDecimal() * Convert.ToDecimal(masterSettings.ExchangeRate));
string str10 = row["PresentIntegral"].ToString();
string str9 = this.IsDelayedLoading ? (" data-url=" + str4 + " ") : string.Empty;
if (this.IsDelayedLoading)
{
node2.InnerHtml = node2.InnerHtml.Insert((node2.InnerHtml.IndexOf("$ThumbnailUrl$") + 1) + "$ThumbnailUrl$".Length, str9);
}
sb.AppendLine(node2.InnerHtml.Replace("$Url$", newValue).Replace("$ThumbnailUrl$", this.IsDelayedLoading ? string.Empty : str4).Replace("$ProductName$", str6).Replace("$MarketPrice$", str7).Replace("$RankPrice$", str8).Replace("$PresentIntegral$", str10));
}
if (innerHtml.IndexOf("</foreach>") > -1)
{
sb.AppendLine(innerHtml.Substring(innerHtml.IndexOf("</foreach>") + 10));
}
}