TemplateNode ConvertXmlToTemplate(XmlNode element) { TemplateNode renderTreeNode = new TemplateNode(element.Name); foreach (XmlAttribute attr in element.Attributes) { if (ForELAttributeName.Equals(attr.Name)) // process el-for { renderTreeNode.forExpress = ForDataBindExpress.Parse(attr.Value); } else if (IfELAttributeName.Equals(attr.Name)) // process el-if { renderTreeNode.ifExpress = IfDataBindExpress.Parse(attr.Value); } //else if (OnceELAttributeName.Equals(attr.Name)) // process el-once //{ // var onceExpress = OnceDataBindExpress.Parse(attr.Value); // if (onceExpress != null) // { // renderTreeNode.onceExpressList.AddLast(onceExpress); // } //} else if (BindELAttributePrefix.Equals(attr.Prefix)) // process el-bind:width="item.width" { var attrExpress = AttributeDataBindExpress.Parse(attr.Value, attr.LocalName); if (attrExpress != null) { renderTreeNode.attributeDataBindExpressList.AddLast(attrExpress); } } else { // try process style ProcessTemplateStyle(renderTreeNode.nodeStyle, attr.Name, attr.Value); } renderTreeNode.attributes[attr.Name] = attr.Value; } // process children // render children foreach (XmlNode ele in element.ChildNodes) { if (XmlNodeType.Element == ele.NodeType) { var trn = ConvertXmlToTemplate(ele); renderTreeNode.Children.Add(trn); } else if (XmlNodeType.Text == ele.NodeType) { renderTreeNode.textDataBindExpress = TextDataBindExpress.Parse(ele.Value); } } return(renderTreeNode); }
/// <summary> /// faild parse return null, otherwise return DataBindObjectExpress /// </summary> /// <param name="express"></param> /// <returns></returns> public static ForDataBindExpress Parse(string express) { if (express == null) { return(null); } express = express.Trim(); int index = express.IndexOf(forInToken); if (index < 0) { return(null); } var forExp = new ForDataBindExpress(); forExp.express = express; forExp.IteratorName = express.Substring(0, index).Trim(); forExp.objectExpress = ObjectDataBindExpress.Parse(express.Substring(index + 2).Trim()); return(forExp.objectExpress != null ? forExp : null); }