Beispiel #1
0
 private void WriteString(string value)
 {
     if (_lastItemWasAtomic)
     {
         // Insert space character between adjacent atomic values
         _xwrt.WriteWhitespace(" ");
     }
     else
     {
         _lastItemWasAtomic = true;
     }
     _xwrt.WriteString(value);
 }
Beispiel #2
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);
            }
        }
        /// <summary>
        /// Create a document containing a root node and a single text node child with "text" as its text value.
        /// This method is thread-safe, and is always guaranteed to return the exact same document, no matter how many
        /// threads have called it concurrently.
        /// </summary>
        public XPathNavigator GetNavigator(string text, string baseUri, XmlNameTable nameTable)
        {
            if (this.cache == null)
            {
                // Create XPathDocument
                XPathDocument doc    = new XPathDocument(nameTable);
                XmlRawWriter  writer = doc.LoadFromWriter(XPathDocument.LoadFlags.AtomizeNames, baseUri);
                writer.WriteString(text);
                writer.Close();

                this.cache = doc;
            }

            return(((XPathDocument)this.cache).CreateNavigator());
        }
Beispiel #4
0
        //------------------------------------------------------------------------
        // ToNode (internal type to internal type)
        //------------------------------------------------------------------------

        public static XPathNavigator ToNode(XPathItem item)
        {
            XsltLibrary.CheckXsltValue(item);

            if (!item.IsNode)
            {
                // Create Navigator over text node containing string value of item
                XPathDocument doc    = new XPathDocument();
                XmlRawWriter  writer = doc.LoadFromWriter(XPathDocument.LoadFlags.AtomizeNames, string.Empty);
                writer.WriteString(ToString(item));
                writer.Close();
                return(doc.CreateNavigator());
            }

            RtfNavigator?rtf = item as RtfNavigator;

            if (rtf != null)
            {
                return(rtf.ToNavigator());
            }

            return((XPathNavigator)item);
        }
Beispiel #5
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);
        }