Example #1
0
        }         // WriteXmlToString(xmlDoc)

        #endregion

        #region Save a system-specific type to a xml-value
        /// <summary>
        /// Convert xml type to string
        /// </summary>
        /// <param name="typeValue">Type value</param>
        /// <returns>String</returns>
        public static string ConvertXmlTypeToString(object typeValue)
        {
            // Special save handling only for the date (at the moment)
            if (typeValue.GetType() == new DateTime().GetType())
            {
                return(CStringHelper.WriteIsoDate((DateTime)typeValue));
            }             // if (typeValue.GetType)
            else
            {
                return(typeValue.ToString());
            }     // else
        }         // ConvertXmlTypeToString(typeValue)
Example #2
0
        }         // GetXmlIntValue(reader)

        /// <summary>
        /// Get xml float value, will return 0 if it does not exists or
        /// isn't a float. Will use the "value" attribute.
        /// </summary>
        /// <param name="reader">Reader</param>
        /// <returns>Float</returns>
        public static float GetXmlFloatValue(XmlReader reader)
        {
            string str = reader.GetAttribute("value");

            float ret = 0;

            //float.TryParse(str, out ret);
            if (CStringHelper.IsNumericFloat(str))
            {
                ret = Convert.ToSingle(str, NumberFormatInfo.InvariantInfo);
            }

            return(ret);
        }         // GetXmlFloatValue(reader)
Example #3
0
        }         // GetXmlAttribute(reader, attributeName)

        /// <summary>
        /// Get xml int value, will return 0 if it does not exists or
        /// isn't an int. Will use the "value" attribute.
        /// </summary>
        /// <param name="reader">Reader</param>
        /// <returns>Float</returns>
        public static int GetXmlIntValue(XmlReader reader)
        {
            string str = reader.GetAttribute("value");

            int ret = 0;

            //int.TryParse(str, out ret);
            if (CStringHelper.IsNumericInt(str))
            {
                ret = Convert.ToInt32(str);
            }

            return(ret);
        }         // GetXmlIntValue(reader)
Example #4
0
        }         // GetXmlAttribute(node, attributeName)

        /// <summary>
        /// Get xml int value, will return 0 if it does not exists or
        /// isn't an int. Will use the "value" attribute.
        /// </summary>
        /// <param name="node">Node</param>
        /// <returns>Float</returns>
        public static int GetXmlIntValue(XmlNode node)
        {
            string str = GetXmlAttribute(node, "value");

            int ret = 0;

            //int.TryParse(str, out ret);
            if (CStringHelper.IsNumericInt(str))
            {
                ret = Convert.ToInt32(str);
            }

            return(ret);
        }         // GetXmlIntValue(node)
Example #5
0
        /// <summary>
        /// Get directory attribute
        /// </summary>
        /// <param name="node">Node</param>
        /// <returns>String</returns>
        public static string GetDirectoryAttribute(XmlNode node)
        {
            string ret = GetXmlAttribute(node, DefaultDirectoryAttributeName);

            if (String.IsNullOrEmpty(ret))
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    if (CStringHelper.Compare(childNode.Name,
                                              DefaultDirectoryAttributeName))
                    {
                        return(childNode.Value);
                    }
                }
            }             // if (String.IsNullOrEmpty)

            return(ret);
        }         // GetDirectoryAttribute(node)
Example #6
0
        }         // GetXmlFloatValue(reader)

        #endregion

        #region XmlDocument find and get nodes helpers
        /// <summary>
        /// Find node in the root level of the xml document (main nodes)
        /// </summary>
        /// <param name="xmlDoc">Xml doc</param>
        /// <param name="xmlNodeName">Xml node name</param>
        /// <returns>Xml node</returns>
        public static XmlNode FindNodeInRoot(XmlDocument xmlDoc,
                                             string xmlNodeName)
        {
            if (xmlDoc == null)
            {
                return(null);
            }

            foreach (XmlNode node in xmlDoc.ChildNodes)
            {
                if (CStringHelper.Compare(node.Name, xmlNodeName))
                {
                    return(node);
                }
            }

            // Not found
            return(null);
        }         // FindNodeInRoot(xmlDoc, xmlNodeName)
Example #7
0
        }         // FindNode(xmlDoc, xmlNodeName)

        /// <summary>
        /// Get xml attribute, will return "" if not found.
        /// </summary>
        /// <param name="node">Node</param>
        /// <param name="attributeName">Attribute name</param>
        /// <returns>String</returns>
        public static string GetXmlAttribute(
            XmlNode node, string attributeName)
        {
            if (node == null || node.Attributes == null)
            {
                return("");
            }

            foreach (XmlNode attribute in node.Attributes)
            {
                if (CStringHelper.Compare(attribute.Name, attributeName))
                {
                    return(attribute.Value == null ? "" : attribute.Value);
                }
            }

            // Not found, just return empty string
            return("");
        }         // GetXmlAttribute(node, attributeName)