예제 #1
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);
        }
예제 #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);
        }