System.Xml.XmlDataDocument.IsTextLikeNode C# (CSharp) Méthode

IsTextLikeNode() static private méthode

static private IsTextLikeNode ( XmlNode n ) : bool
n XmlNode
Résultat bool
        internal static bool IsTextLikeNode(XmlNode n)
        {
            switch (n.NodeType)
            {
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    return true;

                case XmlNodeType.EntityReference:
                    Debug.Assert(false);
                    return false;

                default:
                    return false;
            }
        }

Usage Example

Exemple #1
0
        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();
                }
            }

            if (value == null)
            {
                value = String.Empty;
            }

            return(value);
        }
All Usage Examples Of System.Xml.XmlDataDocument::IsTextLikeNode
XmlDataDocument