예제 #1
0
 /// <summary>
 /// Trims the contents of an XmlNode and returns a string
 /// </summary>
 /// <param name="node">The node to be converted into a string</param>
 /// <param name="defValue">The string to be returned if the contents of the node is empty</param>
 /// <returns></returns>
 public static string Clean(XmlNode node, bool preserveEmptyStrings)
 {
     //xmlelement innertext
     if (node != null)
     {
         return(XmlStrings.Clean(node, null, preserveEmptyStrings));
     }
     else
     {
         return(null);
     }
 }
예제 #2
0
 /// <summary>
 /// Trims the contents of an XmlNode and returns a string
 /// </summary>
 /// <param name="node">The node to be converted into a string</param>
 /// <param name="defValue">The string to be returned if the contents of the node is empty</param>
 /// <returns>The trimmed string if it != null or empty, otherwise returns defValue</returns>
 public static string Clean(XmlNode node, string defValue)
 {
     //xmlelement innertext
     if (node != null)
     {
         return(XmlStrings.Clean(node, defValue, false));
     }
     else
     {
         return(defValue);
     }
 }
예제 #3
0
        /// <summary>
        /// Returns a Trimmed String passed in as an XmlNode, null if the node is null
        /// </summary>
        /// <param name="node">The node to be converted into a string</param>
        /// <returns>The trimmed string if it != null or empty, otherwise returns null</returns>
        public static string Clean(XmlNode node)
        {
            //if node is xmlelement do what u need to do

            //xmlelement innertext
            if (node != null)
            {
                return(XmlStrings.Clean(node, null, false));
            }
            else
            {
                return(null);
            }
            //xmlattribute  value
        }
예제 #4
0
        /// <summary>
        /// Converts an Object to Int
        /// </summary>
        /// <param name="node">The object to be converted, defValue and throwError</param>
        /// <param name="defValue">defValue siginfies the default value for the int returned</param>
        /// <param name="throwError">throwError signifies if error should be thrown incase of invalid object</param>
        /// <returns>The integer if object is != null, error if throwError is true,default value if throwError is false</returns>
        public static uint ToUInt(XmlNode node, uint defValue, bool throwError)
        {
            string s = null;

            try
            {
                //s = Clean(node);
                s = XmlStrings.Clean(node);

                if (s == null)
                {
                    throw new NCIStringConversionFailedException("Node could not be converted to UInt. Please check input Data.");
                }
                else
                {
                    return(Convert.ToUInt32(s));//converts to 32 bit unsigned int
                }
            }
            catch (NCIStringConversionFailedException ex)
            {
                if (throwError)
                {
                    throw new NCIStringConversionFailedException("Could not convert NodeType", ex);
                }
                else
                {
                    return(defValue);
                }
            }
            catch (FormatException ex)
            {
                if (throwError)
                {
                    throw new NCIStringConversionFailedException("Could not convert NodeType cannot be converted", ex);
                }
                else
                {
                    return(defValue);
                }
            }

            return(Strings.ToUInt(s));
        }
예제 #5
0
        /// <summary>
        /// Converts an XmlNode to a Guid
        /// </summary>
        /// <param name="node">The object to be converted</param>
        /// <param name="defValue">defValue siginfies the default value for the Guid returned</param>
        /// <param name="throwError">throwError signifies if error should be thrown incase of invalid object</param>
        /// <returns>The Guid value if obj is != null</returns>
        public static Guid ToGuid(XmlNode node, Guid defValue, bool throwError)
        {
            string s = null;

            try
            {
                s = XmlStrings.Clean(node);


                if (s == null)
                {
                    throw new NCIStringConversionFailedException("Node could not be converted to Guid. Please check input Data.");
                }
                else
                {
                    return(new Guid(s));
                }
            }
            catch (NCIStringConversionFailedException ex)
            {
                if (throwError)
                {
                    throw new NCIStringConversionFailedException("Could not convert NodeType ", ex);
                }
                else
                {
                    return(defValue);
                }
            }
            catch (FormatException ex)
            {
                if (throwError)
                {
                    throw new NCIStringConversionFailedException("Could not convert NodeType cannot be converted", ex);
                }
                else
                {
                    return(defValue);
                }
            }
            return(new Guid(s));
        }