Esempio n. 1
0
        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);
        }
Esempio n. 2
0
            /// <summary>
            /// fail return null
            /// </summary>
            /// <returns></returns>
            public static AttributeDataBindExpress Parse(string express, string targetName)
            {
                if ("".Equals(targetName))
                {
                    return(null);
                }

                var attributeExpress = new AttributeDataBindExpress();

                attributeExpress.TargetName    = targetName;
                attributeExpress.express       = express;
                attributeExpress.objectExpress = ObjectDataBindExpress.Parse(express);
                return(attributeExpress.objectExpress != null ? attributeExpress : null);
            }