示例#1
0
        public static string GetAttr(XmlNode node, string name, string def)
        {
            string s = def;

            name = name.ToLower();
            if (node != null)
            {
                if (node.Attributes != null)
                {
                    foreach (XmlNode atr in node.Attributes)
                    {
                        if (atr.Name.ToLower() == name)
                        {
                            if (atr.Value != "")
                            {
                                s = atr.Value;
                            }
                            return(s);
                        }
                    }
                }
                foreach (XmlNode child in node.ChildNodes)
                {
                    if (child.Name.ToLower() == name)
                    {
                        return(XFunc.GetText(child, s));
                    }
                }
            }
            return(s);
        }
示例#2
0
        public static string GetText(XmlNode node, string def)
        {
            string  r = def;
            XmlNode n = XFunc.GetText(node);

            if (n != null)
            {
                r = n.Value;
            }
            return(r);
        }
示例#3
0
 public static XmlNode SetAttrs(XmlNode node, params object[] parms)
 {
     for (int i = 0; i < parms.Length - 1; i += 2)
     {
         if (parms[i] != null && parms[i + 1] != null)
         {
             XFunc.SetAttr(node, parms[i].ToString(), parms[i + 1].ToString());
         }
     }
     return(node);
 }
示例#4
0
 public static string GetChildText(XmlNode node, string child, string def)
 {
     foreach (XmlNode n in node.ChildNodes)
     {
         if (n.NodeType == XmlNodeType.Element && n.Name == child)
         {
             return(XFunc.GetText(n, def));
         }
     }
     return(def);
 }
示例#5
0
        public static Guid GetAttr(XmlNode node, string name, Guid def)
        {
            Guid   guid = def;
            string s    = XFunc.GetAttr(node, name, "");

            if (s != "")
            {
                guid = new Guid(s);
            }
            return(guid);
        }
示例#6
0
        public static bool GetAttr(XmlNode node, string name, bool def)
        {
            bool   r = def;
            string s = XFunc.GetAttr(node, name, "");

            if (s != "")
            {
                s = s.ToLower();
                r = (s == "1") || (s == "true");
            }
            return(r);
        }
示例#7
0
        public static DateTime GetAttr(XmlNode node, string name, DateTime def)
        {
            DateTime i = def;
            string   s = XFunc.GetAttr(node, name, "");

            if (s != "")
            {
                try
                {
                    i = Convert.ToDateTime(s);
                }
                catch { }
            }
            return(i);
        }
示例#8
0
        public static long GetAttr(XmlNode node, string name, long def)
        {
            long   i = def;
            string s = XFunc.GetAttr(node, name, "");

            if (s != "")
            {
                try
                {
                    i = Convert.ToInt64(s);
                }
                catch { }
            }
            return(i);
        }
示例#9
0
        public static int GetAttr(XmlNode node, string name, int def)
        {
            int    i = def;
            string s = XFunc.GetAttr(node, name, "");

            if (s != "")
            {
                try
                {
                    i = Convert.ToInt32(s);
                }
                catch { }
            }
            return(i);
        }
示例#10
0
        public static void SetText(XmlNode node, string val)
        {
            XmlNode n = XFunc.GetText(node);

            if (val == "")
            {
                if (n != null)
                {
                    node.RemoveChild(n);
                }
            }
            else
            {
                if (n == null)
                {
                    n = node.OwnerDocument.CreateTextNode(val);
                    node.AppendChild(n);
                }
                else
                {
                    n.Value = val;
                }
            }
        }