System.Xml.RegionIterator.NextInitialTextLikeNodes C# (CSharp) Méthode

NextInitialTextLikeNodes() private méthode

private NextInitialTextLikeNodes ( string &value ) : bool
value string
Résultat bool
        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.Assert(false);
                }
            }
#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;
        }

Usage Example

Exemple #1
0
        private void SynchronizeRowFromRowElementEx(XmlBoundElement rowElement, ArrayList rowElemList)
        {
            Debug.Assert(rowElement != null);
            Debug.Assert(rowElement.Row != null);
            Debug.Assert(DataSet.EnforceConstraints == false);

            DataRow row = rowElement.Row;
            Debug.Assert(row != null);
            DataTable table = row.Table;

            Hashtable foundColumns = new Hashtable();
            string xsi_attrVal = string.Empty;

            RegionIterator iter = new RegionIterator(rowElement);
            bool fMore;
            // If present, fill up the TextOnly column
            DataColumn column = GetTextOnlyColumn(row);
            if (column != null)
            {
                foundColumns[column] = column;
                string value;
                fMore = iter.NextInitialTextLikeNodes(out value);
                if (value.Length == 0 && (((xsi_attrVal = rowElement.GetAttribute(XSI_NIL)) == "1") || xsi_attrVal == "true"))
                    row[column] = DBNull.Value;
                else
                    SetRowValueFromXmlText(row, column, value);
            }
            else
                fMore = iter.Next();

            // Fill up the columns mapped to an element
            while (fMore)
            {
                XmlElement e = iter.CurrentNode as XmlElement;
                if (e == null)
                {
                    fMore = iter.Next();
                    continue;
                }

                XmlBoundElement be = e as XmlBoundElement;
                if (be != null && be.Row != null)
                {
                    if (rowElemList != null)
                        rowElemList.Add(e);
                    // Skip over sub-regions
                    fMore = iter.NextRight();
                    continue;
                }

                DataColumn c = _mapper.GetColumnSchemaForNode(rowElement, e);
                if (c != null)
                {
                    Debug.Assert(c.Table == row.Table);
                    if (foundColumns[c] == null)
                    {
                        foundColumns[c] = c;
                        string value;
                        fMore = iter.NextInitialTextLikeNodes(out value);
                        if (value.Length == 0 && (((xsi_attrVal = e.GetAttribute(XSI_NIL)) == "1") || xsi_attrVal == "true"))
                            row[c] = DBNull.Value;
                        else
                            SetRowValueFromXmlText(row, c, value);
                        continue;
                    }
                }

                fMore = iter.Next();
            }

            //
            // Walk the attributes to find attributes that map to columns.
            //
            foreach (XmlAttribute attr in rowElement.Attributes)
            {
                DataColumn c = _mapper.GetColumnSchemaForNode(rowElement, attr);

                if (c != null)
                {
                    if (foundColumns[c] == null)
                    {
                        foundColumns[c] = c;
                        SetRowValueFromXmlText(row, c, attr.Value);
                    }
                }
            }

            // Null all columns values that aren't represented in the tree
            foreach (DataColumn c in row.Table.Columns)
            {
                if (foundColumns[c] == null && !IsNotMapped(c))
                {
                    if (!c.AutoIncrement)
                        SetRowValueToNull(row, c);
                    else
                        c.Init(row._tempRecord);
                }
            }
        }