System.Xml.RegionIterator.GetInitialTextFromNodes C# (CSharp) Method

GetInitialTextFromNodes() private static method

private static GetInitialTextFromNodes ( XmlNode &n ) : string
n XmlNode
return string
        private static string GetInitialTextFromNodes(ref XmlNode n)
        {
            string value = null;

            if (n != null)
            {
                // don't consider whitespace
                while (n.NodeType == XmlNodeType.Whitespace)
                {
                    n = n.NextSibling;
                    if (n == null)
                    {
                        return string.Empty;
                    }
                }

                if (XmlDataDocument.IsTextLikeNode(n) && (n.NextSibling == null || !XmlDataDocument.IsTextLikeNode(n.NextSibling)))
                {
                    // don't use string builder if only one text node exists
                    value = n.Value;
                    n = n.NextSibling;
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    while (n != null && XmlDataDocument.IsTextLikeNode(n))
                    {
                        // Ignore non-significant whitespace nodes
                        if (n.NodeType != XmlNodeType.Whitespace)
                        {
                            sb.Append(n.Value);
                        }
                        n = n.NextSibling;
                    }
                    value = sb.ToString();
                }
            }

            return value ?? string.Empty;
        }
    }