Пример #1
0
        public static object FromXml(string xml, XmlAlias alias)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            XmlNode node = doc.DocumentElement;

            return(handleOneNode(alias, node, null, null));
        }
Пример #2
0
        private static object handleOneNode(XmlAlias alias, XmlNode node, object obj, string parentName)
        {
            if (node != null)
            {
                string name     = GetClassName(node);
                object childObj = alias.GetObject(name);

                if (childObj == null)
                {
                    return(obj);
                }

                if (obj == null)
                {
                    obj = childObj;
                }
                else
                {
                    alias.SetField(parentName, obj, childObj, node.Name);
                }

                if (node.Attributes != null)
                {
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Name != "class")
                        {
                            alias.SetFieldValue(name, childObj, attr.Name, attr.Value);
                        }
                    }
                }

                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name != "version")
                    {
                        handleOneNode(alias, child, childObj, name);
                    }
                    else
                    {
                        try
                        {
                            version = child.FirstChild.Value;
                        }
                        catch
                        {
                            _logger.ErrorFormat("version failed !");
                        }
                    }
                }
            }

            return(obj);
        }
Пример #3
0
        private static object handleOneNode(XmlAlias alias, XmlNode node, object obj, string parentName)
        {
            if (node != null)
            {
                string name     = GetClassName(node);
                object childObj = alias.GetObject(name);

                if (childObj == null)
                {
                    return(obj);
                }

                if (obj == null)
                {
                    obj = childObj;
                }
                else
                {
                    alias.SetField(parentName, obj, childObj, node.Name);
                }

                if (node.Attributes != null)
                {
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Name != "class")
                        {
                            alias.SetFieldValue(name, childObj, attr.Name, attr.Value);
                        }
                    }
                }

                foreach (XmlNode child in node.ChildNodes)
                {
                    handleOneNode(alias, child, childObj, name);
                }
            }

            return(obj);
        }