public static LowerNameValueCollection GetAttributes(string stlElement, bool isInnerElement) { var attributes = new LowerNameValueCollection(); try { var xmlDocument = GetXmlDocument(stlElement, isInnerElement); XmlNode node = xmlDocument.DocumentElement; if (node != null) { node = node.FirstChild; if (node.Attributes != null) { foreach (XmlAttribute attribute in node.Attributes) { attributes.Set(attribute.Name, attribute.Value); } } } } catch { // ignored } return(attributes); }
//TODO:测试 public static string GetInnerXml(string stlElement, bool isInnerElement, LowerNameValueCollection attributes) { var retval = string.Empty; try { var xmlDocument = GetXmlDocument(stlElement, isInnerElement); XmlNode node = xmlDocument.DocumentElement; if (node != null) { node = node.FirstChild; retval = node.InnerXml; if (attributes != null && node.Attributes != null) { foreach (XmlAttribute attribute in node.Attributes) { attributes.Set(attribute.Name, attribute.Value); } } } } catch { // ignored } return(retval); }
public static string Parse(string stlElement, XmlNode node, PageInfo pageInfo, ContextInfo contextInfoRef) { string parsedContent; var contextInfo = contextInfoRef.Clone(); try { var tagLevel = 1; var totalNum = 0; var isOrderByCount = false; var theme = "default"; var isDynamic = false; var isInnerXml = !string.IsNullOrEmpty(node.InnerXml); var attributes = new LowerNameValueCollection(); var ie = node.Attributes?.GetEnumerator(); if (ie != null) { while (ie.MoveNext()) { var attr = (XmlAttribute)ie.Current; if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeTagLevel)) { tagLevel = TranslateUtils.ToInt(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeTotalNum)) { totalNum = TranslateUtils.ToInt(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsOrderByCount)) { isOrderByCount = TranslateUtils.ToBool(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeTheme)) { theme = attr.Value; } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeContext)) { contextInfo.ContextType = EContextTypeUtils.GetEnumType(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsDynamic)) { isDynamic = TranslateUtils.ToBool(attr.Value); } else { attributes.Set(attr.Name, attr.Value); } } } parsedContent = isDynamic ? StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo) : ParseImpl(stlElement, isInnerXml, pageInfo, contextInfo, tagLevel, totalNum, isOrderByCount, theme); } catch (Exception ex) { parsedContent = StlParserUtility.GetStlErrorMessage(ElementName, ex); } return(parsedContent); }
public static string Parse(string stlElement, XmlNode node, PageInfo pageInfo, ContextInfo contextInfo) { string parsedContent; try { var channelIndex = string.Empty; var channelName = string.Empty; var upLevel = 0; var topLevel = -1; var groupChannel = string.Empty; var groupChannelNot = string.Empty; var title = string.Empty; var isLoading = false; var isShowContentNum = false; var isShowTreeLine = true; var currentFormatString = "<strong>{0}</strong>"; var isDynamic = false; var attributes = new LowerNameValueCollection(); var ie = node.Attributes?.GetEnumerator(); if (ie != null) { while (ie.MoveNext()) { var attr = (XmlAttribute)ie.Current; if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeChannelIndex)) { channelIndex = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeChannelName)) { channelName = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeUpLevel)) { upLevel = TranslateUtils.ToInt(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeTopLevel)) { topLevel = TranslateUtils.ToInt(attr.Value); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeGroupChannel)) { groupChannel = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeGroupChannelNot)) { groupChannelNot = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeTitle)) { title = StlEntityParser.ReplaceStlEntitiesForAttributeValue(attr.Value, pageInfo, contextInfo); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsLoading)) { isLoading = TranslateUtils.ToBool(attr.Value, false); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsShowContentNum)) { isShowContentNum = TranslateUtils.ToBool(attr.Value, false); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsShowTreeLine)) { isShowTreeLine = TranslateUtils.ToBool(attr.Value, true); } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeCurrentFormatString)) { currentFormatString = attr.Value; if (!StringUtils.Contains(currentFormatString, "{0}")) { currentFormatString += "{0}"; } } else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsDynamic)) { isDynamic = TranslateUtils.ToBool(attr.Value); } else { attributes.Set(attr.Name, attr.Value); } } } if (isDynamic) { parsedContent = StlDynamic.ParseDynamicElement(stlElement, pageInfo, contextInfo); } else { parsedContent = isLoading ? ParseImplAjax(pageInfo, contextInfo, channelIndex, channelName, upLevel, topLevel, groupChannel, groupChannelNot, title, isShowContentNum, isShowTreeLine, currentFormatString) : ParseImplNotAjax(pageInfo, contextInfo, channelIndex, channelName, upLevel, topLevel, groupChannel, groupChannelNot, title, isShowContentNum, isShowTreeLine, currentFormatString); } } catch (Exception ex) { parsedContent = StlParserUtility.GetStlErrorMessage(ElementName, ex); } return(parsedContent); }