예제 #1
0
        /// <summary>
        /// Send cached, non-overridden attributes to the specified writer.  Calling this method has
        /// the side effect of clearing the attribute cache.
        /// </summary>
        internal override void StartElementContent()
        {
            FlushAttributes();

            // Call StartElementContent on wrapped writer
            _wrapped.StartElementContent();
        }
예제 #2
0
        public Processor.OutputResult RecordDone(RecordBuilder record)
        {
            Debug.Assert(record != null);

            BuilderInfo mainNode = record.MainNode;

            _documentIndex++;
            switch (mainNode.NodeType)
            {
            case XmlNodeType.Element:
            {
                _wr.WriteStartElement(mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI);
                for (int attrib = 0; attrib < record.AttributeCount; attrib++)
                {
                    _documentIndex++;
                    Debug.Assert(record.AttributeList[attrib] is BuilderInfo);
                    BuilderInfo attrInfo = (BuilderInfo)record.AttributeList[attrib] !;
                    if (attrInfo.NamespaceURI == XmlReservedNs.NsXmlNs)
                    {
                        if (attrInfo.Prefix.Length == 0)
                        {
                            _wr.WriteNamespaceDeclaration(string.Empty, attrInfo.Value);
                        }
                        else
                        {
                            _wr.WriteNamespaceDeclaration(attrInfo.LocalName, attrInfo.Value);
                        }
                    }
                    else
                    {
                        _wr.WriteAttributeString(attrInfo.Prefix, attrInfo.LocalName, attrInfo.NamespaceURI, attrInfo.Value);
                    }
                }

                _wr.StartElementContent();

                if (mainNode.IsEmptyTag)
                {
                    _wr.WriteEndElement(mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI);
                }
                break;
            }

            case XmlNodeType.Text:
                _wr.WriteString(mainNode.Value);
                break;

            case XmlNodeType.Whitespace:
                break;

            case XmlNodeType.SignificantWhitespace:
                _wr.WriteString(mainNode.Value);
                break;

            case XmlNodeType.ProcessingInstruction:
                _wr.WriteProcessingInstruction(mainNode.LocalName, mainNode.Value);
                break;

            case XmlNodeType.Comment:
                _wr.WriteComment(mainNode.Value);
                break;

            case XmlNodeType.Document:
                break;

            case XmlNodeType.EndElement:
                _wr.WriteEndElement(mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI);
                break;

            default:
                Debug.Fail($"Invalid NodeType on output: {mainNode.NodeType}");
                break;
            }
            record.Reset();
            return(Processor.OutputResult.Continue);
        }
예제 #3
0
        private void CopyNode(XPathNavigator nav)
        {
            XPathNodeType nodeType;
            int           iLevel = 0;

            while (true)
            {
                if (CopyShallowNode(nav))
                {
                    nodeType = nav.NodeType;
                    if (nodeType == XPathNodeType.Element)
                    {
                        // Copy attributes
                        if (nav.MoveToFirstAttribute())
                        {
                            do
                            {
                                CopyShallowNode(nav);
                            }while (nav.MoveToNextAttribute());
                            nav.MoveToParent();
                        }

                        // Copy namespaces in document order (navigator returns them in reverse document order)
                        XPathNamespaceScope nsScope = (iLevel == 0) ? XPathNamespaceScope.ExcludeXml : XPathNamespaceScope.Local;
                        if (nav.MoveToFirstNamespace(nsScope))
                        {
                            CopyNamespaces(nav, nsScope);
                            nav.MoveToParent();
                        }

                        _xwrt.StartElementContent();
                    }

                    // If children exist, move down to next level
                    if (nav.MoveToFirstChild())
                    {
                        iLevel++;
                        continue;
                    }
                    else
                    {
                        // EndElement
                        if (nav.NodeType == XPathNodeType.Element)
                        {
                            _xwrt.WriteEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                        }
                    }
                }

                // No children
                while (true)
                {
                    if (iLevel == 0)
                    {
                        // The entire subtree has been copied
                        return;
                    }

                    if (nav.MoveToNext())
                    {
                        // Found a sibling, so break to outer loop
                        break;
                    }

                    // No siblings, so move up to previous level
                    iLevel--;
                    nav.MoveToParent();

                    // EndElement
                    if (nav.NodeType == XPathNodeType.Element)
                    {
                        _xwrt.WriteFullEndElement(nav.Prefix, nav.LocalName, nav.NamespaceURI);
                    }
                }
            }
        }