Пример #1
0
        //-----------------------------------------------
        // Helper methods
        //-----------------------------------------------

        private void FlushAttributes()
        {
            int    idx = 0, idxNext;
            string localName;

            while (idx != _numEntries)
            {
                // Get index of next attribute's name (0 if this is the last attribute)
                idxNext = _arrAttrs[idx].NextNameIndex;
                if (idxNext == 0)
                {
                    idxNext = _numEntries;
                }

                // If localName is null, then this is a duplicate attribute that has been marked as "deleted"
                localName = _arrAttrs[idx].LocalName;
                if (localName != null)
                {
                    string prefix = _arrAttrs[idx].Prefix;
                    string ns     = _arrAttrs[idx].Namespace;

                    _wrapped.WriteStartAttribute(prefix, localName, ns);

                    // Output all of this attribute's text or typed values
                    while (++idx != idxNext)
                    {
                        string text = _arrAttrs[idx].Text;

                        if (text != null)
                        {
                            _wrapped.WriteString(text);
                        }
                        else
                        {
                            _wrapped.WriteValue(_arrAttrs[idx].Value);
                        }
                    }

                    _wrapped.WriteEndAttribute();
                }
                else
                {
                    // Skip over duplicate attributes
                    idx = idxNext;
                }
            }

            // Notify event listener that attributes have been flushed
            if (_onRemove != null)
            {
                _onRemove(_wrapped);
            }
        }
Пример #2
0
        private bool CopyShallowNode(XPathNavigator nav)
        {
            bool mayHaveChildren = false;

            switch (nav.NodeType)
            {
            case XPathNodeType.Element:
                _xwrt.WriteStartElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                mayHaveChildren = true;
                break;

            case XPathNodeType.Attribute:
                _xwrt.WriteStartAttribute(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                _xwrt.WriteString(nav.Value);
                _xwrt.WriteEndAttribute();
                break;

            case XPathNodeType.Text:
                _xwrt.WriteString(nav.Value);
                break;

            case XPathNodeType.SignificantWhitespace:
            case XPathNodeType.Whitespace:
                _xwrt.WriteWhitespace(nav.Value);
                break;

            case XPathNodeType.Root:
                mayHaveChildren = true;
                break;

            case XPathNodeType.Comment:
                _xwrt.WriteComment(nav.Value);
                break;

            case XPathNodeType.ProcessingInstruction:
                _xwrt.WriteProcessingInstruction(nav.LocalName, nav.Value);
                break;

            case XPathNodeType.Namespace:
                _xwrt.WriteNamespaceDeclaration(nav.LocalName, nav.Value);
                break;

            default:
                Debug.Fail($"Unexpected node type {nav.NodeType}");
                break;
            }

            return(mayHaveChildren);
        }