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); }
// Get the initial text value for the current node. You should be positioned on the node (element) for // which to get the initial text value, not on the text node. internal bool NextInitialTextLikeNodes(out string value) { Debug.Assert(CurrentNode != null); Debug.Assert(CurrentNode.NodeType == XmlNodeType.Element); #if DEBUG // It's not OK to try to read the initial text value for sub-regions, because we do not know how to revert their initial state if (CurrentNode.NodeType == XmlNodeType.Element && mapper.GetTableSchemaForElement((XmlElement)(CurrentNode)) != null) { if (CurrentNode != _rowElement) { Debug.Fail("Reading the initial text value for sub-regions."); } } #endif ElementState oldState = _rowElement.ElementState; // We do not want to cause any foliation w/ this iterator or use this iterator once the region was defoliated Debug.Assert(oldState != ElementState.None); XmlNode n = CurrentNode.FirstChild; value = GetInitialTextFromNodes(ref n); if (n == null) { // If we have been defoliated, we should have stayed that way Debug.Assert((oldState == ElementState.Defoliated) ? (_rowElement.ElementState == ElementState.Defoliated) : true); // Rollback eventual foliation _rowElement.ElementState = oldState; return(NextRight()); } Debug.Assert(!XmlDataDocument.IsTextLikeNode(n)); _currentNode = n; // If we have been defoliated, we should have stayed that way Debug.Assert((oldState == ElementState.Defoliated) ? (_rowElement.ElementState == ElementState.Defoliated) : true); // Rollback eventual foliation _rowElement.ElementState = oldState; return(true); }
private static string GetInitialTextFromNodes(ref XmlNode n) { string str = null; if (n != null) { 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))) { str = n.Value; n = n.NextSibling; } else { StringBuilder builder = new StringBuilder(); while ((n != null) && XmlDataDocument.IsTextLikeNode(n)) { if (n.NodeType != XmlNodeType.Whitespace) { builder.Append(n.Value); } n = n.NextSibling; } str = builder.ToString(); } } if (str == null) { str = string.Empty; } return(str); }