public static ListInfo GetListInfoByXmlNode(XmlNode node, PageInfo pageInfo, ContextInfo contextInfo, EContextType contextType) { var listInfo = new ListInfo { _contextType = contextType }; var innerXml = node.InnerXml; var itemTemplate = string.Empty; if (!string.IsNullOrEmpty(innerXml)) { var stlElementList = StlParserUtility.GetStlElementList(innerXml); if (stlElementList.Count > 0) { foreach (var theStlElement in stlElementList) { if (StlParserUtility.IsSpecifiedStlElement(theStlElement, StlItemTemplate.ElementName)) { var attributes = new LowerNameValueCollection(); var templateString = StlParserUtility.GetInnerXml(theStlElement, true, attributes); if (!string.IsNullOrEmpty(templateString)) { foreach (var key in attributes.Keys) { if (!StringUtils.EqualsIgnoreCase(key, StlItemTemplate.AttributeType)) { continue; } var type = attributes.Get(key); if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeItem)) { itemTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeHeader)) { listInfo.HeaderTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeFooter)) { listInfo.FooterTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeAlternatingItem)) { listInfo.AlternatingItemTemplate = templateString; } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeSelectedItem)) { if (!string.IsNullOrEmpty(attributes.Get(StlItemTemplate.AttributeSelected))) { var selected = attributes.Get(StlItemTemplate.AttributeSelected); var arraylist = new ArrayList(); if (selected.IndexOf(',') != -1) { arraylist.AddRange(selected.Split(',')); } else { if (selected.IndexOf('-') != -1) { var first = TranslateUtils.ToInt(selected.Split('-')[0]); var second = TranslateUtils.ToInt(selected.Split('-')[1]); for (var i = first; i <= second; i++) { arraylist.Add(i.ToString()); } } else { arraylist.Add(selected); } } foreach (string val in arraylist) { listInfo.SelectedItems.Set(val, templateString); } if (!string.IsNullOrEmpty(attributes.Get(StlItemTemplate.AttributeSelectedValue))) { var selectedValue = attributes.Get(StlItemTemplate.AttributeSelectedValue); listInfo.SelectedValues.Set(selectedValue, templateString); } } } else if (StringUtils.EqualsIgnoreCase(type, StlItemTemplate.TypeSeparator)) { var selectedValue = TranslateUtils.ToInt(attributes.Get(StlItemTemplate.AttributeSelectedValue), 1); if (selectedValue <= 1) { listInfo.SeparatorTemplate = templateString; } else { listInfo.SeparatorRepeatTemplate = templateString; listInfo.SeparatorRepeat = selectedValue; } } } } innerXml = innerXml.Replace(theStlElement, string.Empty); } else if (StlParserUtility.IsSpecifiedStlElement(theStlElement, StlLoading.ElementName)) { var innerBuilder = new StringBuilder(StlParserUtility.GetInnerXml(theStlElement, true)); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); StlParserUtility.XmlToHtml(innerBuilder); listInfo.LoadingTemplate = innerBuilder.ToString(); innerXml = innerXml.Replace(theStlElement, string.Empty); } else if (contextType == EContextType.SqlContent && StlParserUtility.IsSpecifiedStlElement(theStlElement, StlQueryString.ElementName)) { var innerBuilder = new StringBuilder(StlParserUtility.GetInnerXml(theStlElement, true)); StlParserManager.ParseInnerContent(innerBuilder, pageInfo, contextInfo); StlParserUtility.XmlToHtml(innerBuilder); listInfo.QueryString = innerBuilder.ToString(); innerXml = innerXml.Replace(theStlElement, string.Empty); } } } } if (string.IsNullOrEmpty(itemTemplate)) { listInfo.ItemTemplate = !string.IsNullOrEmpty(innerXml) ? innerXml : "<stl:a target=\"_blank\"></stl:a>"; } else { listInfo.ItemTemplate = itemTemplate; } var ie = node.Attributes.GetEnumerator(); var isSetDirection = false;//是否设置了direction属性 while (ie.MoveNext()) { var attr = (XmlAttribute)ie.Current; if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeChannelIndex)) { listInfo.ChannelIndex = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeChannelName)) { listInfo.ChannelName = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeUpLevel)) { listInfo.UpLevel = TranslateUtils.ToInt(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeTopLevel)) { listInfo.TopLevel = TranslateUtils.ToInt(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeScope)) { listInfo.Scope = EScopeTypeUtils.GetEnumType(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsTop)) { listInfo.IsTop = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsRecommend)) { listInfo.IsRecommend = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsHot)) { listInfo.IsHot = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsColor)) { listInfo.IsColor = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeWhere)) { listInfo.Where = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsDynamic)) { listInfo.IsDynamic = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeTotalNum)) { listInfo.TotalNum = TranslateUtils.ToInt(StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo)); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlPageContents.AttributePageNum)) { listInfo.PageNum = TranslateUtils.ToInt(StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo)); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlPageContents.AttributeMaxPage)) { listInfo.MaxPage = TranslateUtils.ToInt(StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo)); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeTitleWordNum)) { listInfo.TitleWordNum = TranslateUtils.ToInt(StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo)); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeStartNum)) { listInfo.StartNum = TranslateUtils.ToInt(StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo)); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeOrder)) { if (contextType == EContextType.Content) { listInfo.OrderByString = StlDataUtility.GetOrderByString(pageInfo.PublishmentSystemId, attr.Value, ETableStyle.BackgroundContent, ETaxisType.OrderByTaxisDesc); } else if (contextType == EContextType.Channel) { listInfo.OrderByString = StlDataUtility.GetOrderByString(pageInfo.PublishmentSystemId, attr.Value, ETableStyle.Channel, ETaxisType.OrderByTaxis); } else if (contextType == EContextType.InputContent) { listInfo.OrderByString = StlDataUtility.GetOrderByString(pageInfo.PublishmentSystemId, attr.Value, ETableStyle.InputContent, ETaxisType.OrderByTaxisDesc); } else { listInfo.OrderByString = attr.Value; } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeGroupChannel)) { listInfo.GroupChannel = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); if (string.IsNullOrEmpty(listInfo.GroupChannel)) { listInfo.GroupChannel = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeGroupChannelNot)) { listInfo.GroupChannelNot = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); if (string.IsNullOrEmpty(listInfo.GroupChannelNot)) { listInfo.GroupChannelNot = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeGroupContent) || StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeGroup)) { listInfo.GroupContent = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); if (string.IsNullOrEmpty(listInfo.GroupContent)) { listInfo.GroupContent = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeGroupContentNot) || StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeGroupNot)) { listInfo.GroupContentNot = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); if (string.IsNullOrEmpty(listInfo.GroupContentNot)) { listInfo.GroupContentNot = "__Empty__"; } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeTags)) { listInfo.Tags = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeColumns)) { listInfo.Columns = TranslateUtils.ToInt(attr.Value); listInfo.Layout = ELayout.Table; if (listInfo.Columns > 1 && isSetDirection == false) { listInfo.Direction = RepeatDirection.Horizontal; } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeDirection)) { listInfo.Layout = ELayout.Table; listInfo.Direction = Converter.ToRepeatDirection(attr.Value); isSetDirection = true; } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeHeight)) { try { listInfo.Height = Unit.Parse(attr.Value); } catch { // ignored } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeWidth)) { try { listInfo.Width = Unit.Parse(attr.Value); } catch { // ignored } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeAlign)) { listInfo.Align = attr.Value; } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeItemHeight)) { try { listInfo.ItemHeight = Unit.Parse(attr.Value); } catch { // ignored } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeItemWidth)) { try { listInfo.ItemWidth = Unit.Parse(attr.Value); } catch { // ignored } } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeItemAlign)) { listInfo.ItemAlign = attr.Value; } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeItemVerticalAlign)) { listInfo.ItemVerticalAlign = attr.Value; } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeItemClass)) { listInfo.ItemClass = attr.Value; } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsImage)) { listInfo.IsImage = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsVideo)) { listInfo.IsVideo = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsFile)) { listInfo.IsFile = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsNoDup)) { listInfo.IsNoDup = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeIsRelatedContents)) { listInfo.IsRelatedContents = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, StlContents.AttributeLayout)) { listInfo.Layout = ELayoutUtils.GetEnumType(attr.Value); } else if (contextType == EContextType.SqlContent && StringUtils.EqualsIgnoreCase(attr.Name, StlSqlContents.AttributeConnectionString)) { listInfo.ConnectionString = attr.Value; } else if (contextType == EContextType.SqlContent && StringUtils.EqualsIgnoreCase(attr.Name, StlSqlContents.AttributeConnectionStringName)) { if (string.IsNullOrEmpty(listInfo.ConnectionString)) { listInfo.ConnectionString = WebConfigUtils.ConnectionString; } } else { listInfo.Others.Set(attr.Name, attr.Value); } } return(listInfo); }