Example #1
0
        /// <summary>
        /// 用XmlElement的信息构造SqlElement类的对象(或继承自SqlElement类的对象)。
        /// </summary>
        /// <param name="sqlNode">SqlElement类的对象(或继承自SqlElement类的对象)</param>
        /// <param name="xmlParent">XmlDocument中的元素</param>
        /// <param name="xnm">集合命名空间范围管理类的对象</param>
        public virtual void FromXml(SqlElement sqlNode, XmlElement xmlParent, XmlNamespaceManager xnm)
        {
            ParserUtil util       = new ParserUtil(xnm);
            XmlElement xmlId      = util.Child(xmlParent, ID);
            XmlElement xmlVersion = util.Child(xmlParent, VERSION);

            //sqlNode.Id = xmlId.InnerText;
            //sqlNode.Version = xmlVersion.InnerText;

            XmlElement xmlChildList = util.Child(xmlParent, CHILDCOLLECTION);

            if (xmlChildList != null)
            {
                XmlNodeList childNodeList = util.Children(xmlChildList, SQLELEMENT);
                if (childNodeList != null)
                {
                    sqlNode.CreateChildCollection();
                    foreach (XmlElement xmlChildNode in childNodeList)
                    {
                        //// 通过反射构造对象。
                        //string fullname = util.AttrStr(xmlChildNode, CLASSFULLNAME);
                        //Assembly ass = Assembly.GetExecutingAssembly();
                        //SqlElement node = ass.CreateInstance(fullname) as SqlElement;

                        int        sqlElementType = util.AttrInt(xmlChildNode, SQLELEMENTTYPE);
                        SqlElement node           = SqlElementFactory.GetSQLElement(sqlElementType);
                        node.FromXml(node, xmlChildNode, xnm);
                        sqlNode.ChildCollection.Add(node);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 将SqlElement的属性写入XmlElement。
        /// </summary>
        /// <param name="sqlNode">SqlElement类的对象(或继承自SqlElement类的对象)</param>
        /// <param name="xmlParent">XmlDocument中的元素</param>
        public virtual void ToXml(SqlElement sqlNode, XmlElement xmlParent)
        {
            //XmlElement xmlId = SerializerUtil.AddElement(xmlParent, ID, sqlNode.Id);
            //XmlElement xmlVersion = SerializerUtil.AddElement(xmlParent, VERSION, sqlNode.Version);
            if (sqlNode.ChildCollection != null)
            {
                XmlElement xmlchildList = SerializerUtil.AddElement(xmlParent, CHILDCOLLECTION);
                foreach (SqlElement childNode in sqlNode.ChildCollection)
                {
                    XmlElement childNodeElement = SerializerUtil.AddElement(xmlchildList, SQLELEMENT);

                    /*
                     * FullName:一个包含 Type 的完全限定名的字符串,其中包括 Type 的命名空间但不包括程序集;
                     * 例如,C# 字符串类型的完全限定名为 System.String。
                     * */
                    //childNodeElement.SetAttribute(CLASSFULLNAME, childNode.GetType().FullName);
                    childNodeElement.SetAttribute(SQLELEMENTTYPE, SqlElementFactory.GetSqlElementType(childNode).ToString());
                    childNode.ToXml(childNode, childNodeElement);
                }
            }
        }