Esempio n. 1
0
        private bool DecideDefaultOutput(BuilderInfo node)
        {
            XsltOutput.OutputMethod method = XsltOutput.OutputMethod.Xml;
            switch (node.NodeType)
            {
            case XmlNodeType.Element:
                if (node.NamespaceURI.Length == 0 && String.Compare(Keywords.s_Html, node.LocalName, /*ignoreCase:*/ true, CultureInfo.InvariantCulture) == 0)
                {
                    method = XsltOutput.OutputMethod.Html;
                }
                break;

            case XmlNodeType.Text:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                if (XmlCharType.IsOnlyWhitespace(node.Value))
                {
                    return(false);
                }
                method = XsltOutput.OutputMethod.Xml;
                break;

            default:
                return(false);
            }
            if (this.processor.SetDefaultOutput(method))
            {
                CacheOuptutProps(processor.Output);
            }
            return(true);
        }
Esempio n. 2
0
        private bool DecideDefaultOutput(BuilderInfo node)
        {
            XsltOutput.OutputMethod method = XsltOutput.OutputMethod.Xml;
            switch (node.NodeType)
            {
            case XmlNodeType.Element:
                if (node.NamespaceURI.Length == 0 && string.Equals("html", node.LocalName, StringComparison.OrdinalIgnoreCase))
                {
                    method = XsltOutput.OutputMethod.Html;
                }
                break;

            case XmlNodeType.Text:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                if (XmlCharType.IsOnlyWhitespace(node.Value))
                {
                    return(false);
                }
                method = XsltOutput.OutputMethod.Xml;
                break;

            default:
                return(false);
            }
            if (_processor.SetDefaultOutput(method))
            {
                CacheOuptutProps(_processor.Output);
            }
            return(true);
        }
Esempio n. 3
0
        internal BuilderInfo Clone()
        {
            BuilderInfo info = new BuilderInfo();

            info.Initialize(this);
            Debug.Assert(info.NodeType != XmlNodeType.Text || XmlCharType.IsOnlyWhitespace(info.Value));
            return(info);
        }
Esempio n. 4
0
        internal BuilderInfo Clone()
        {
            BuilderInfo info = (BuilderInfo)MemberwiseClone();

            // This is for cached nodes only and non whitespace text nodes will not be cached. So we cal loos disableOutputEscaping info.
            info.valueBuilder = new StringBuilder(this.Value);
            info.nextTextInfo = null;
            info.lastTextInfo = this;
            Debug.Assert(info.NodeType != XmlNodeType.Text || XmlCharType.IsOnlyWhitespace(info.Value));
            return(info);
        }
Esempio n. 5
0
        /// <summary>
        /// Override Read in order to search for strippable whitespace, to concatenate adjacent text nodes, and to
        /// resolve entities.
        /// </summary>
        public override bool Read()
        {
            string?ws = null;

            // Clear text value
            _val = null;

            while (base.Read())
            {
                switch (base.NodeType)
                {
                case XmlNodeType.Element:
                    // Push boolean indicating whether whitespace children of this element should be stripped
                    if (!base.IsEmptyElement)
                    {
                        _stkStrip.PushBit(_shouldStrip);

                        // Strip if rules say we should and we're not within the scope of xml:space="preserve"
                        _shouldStrip = _wsRules.ShouldStripSpace(base.LocalName, base.NamespaceURI) && (base.XmlSpace != XmlSpace.Preserve);
                    }
                    break;

                case XmlNodeType.EndElement:
                    // Restore parent shouldStrip setting
                    _shouldStrip = _stkStrip.PopBit();
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    // If preserving adjacent text, don't perform any further checks
                    if (_preserveAdjacent)
                    {
                        return(true);
                    }

                    if (_shouldStrip)
                    {
                        // Reader may report whitespace as Text or CDATA
                        if (XmlCharType.IsOnlyWhitespace(base.Value))
                        {
                            goto case XmlNodeType.Whitespace;
                        }

                        // If whitespace was cached, then prepend it to text or CDATA value
                        if (ws != null)
                        {
                            _val = string.Concat(ws, base.Value);
                        }

                        // Preserve adjacent whitespace
                        _preserveAdjacent = true;
                        return(true);
                    }
                    break;

                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    // If preserving adjacent text, don't perform any further checks
                    if (_preserveAdjacent)
                    {
                        return(true);
                    }

                    if (_shouldStrip)
                    {
                        // Save whitespace until it can be determined whether it will be stripped
                        ws = ws == null ?
                             base.Value :
                             string.Concat(ws, base.Value);

                        // Read next event
                        continue;
                    }
                    break;

                case XmlNodeType.EndEntity:
                    // Read next event
                    continue;
                }

                // No longer preserve adjacent space
                _preserveAdjacent = false;
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        internal int AddBooleanQuery(string xpathQuery)
        {
            string modifiedQuery = XmlCharType.IsOnlyWhitespace(xpathQuery) ? xpathQuery : $"boolean({xpathQuery})";

            return(AddQuery(modifiedQuery));
        }
Esempio n. 7
0
        // Moving through the Stream

        public override bool Read()
        {
            Debug.Assert(this.processor != null || this.state == ReadState.Closed);

            if (this.state != ReadState.Interactive)
            {
                if (this.state == ReadState.Initial)
                {
                    state = ReadState.Interactive;
                }
                else
                {
                    return(false);
                }
            }

            while (true)   // while -- to ignor empty whitespace nodes.
            {
                if (this.haveRecord)
                {
                    this.processor.ResetOutput();
                    this.haveRecord = false;
                }

                this.processor.Execute();

                if (this.haveRecord)
                {
                    CheckCurrentInfo();
                    // check text nodes on whitespaces;
                    switch (this.NodeType)
                    {
                    case XmlNodeType.Text:
                        if (XmlCharType.IsOnlyWhitespace(this.Value))
                        {
                            this.currentInfo.NodeType = XmlNodeType.Whitespace;
                            goto case XmlNodeType.Whitespace;
                        }
                        Debug.Assert(this.Value.Length != 0, "It whould be Whitespace in this case");
                        break;

                    case XmlNodeType.Whitespace:
                        if (this.Value.Length == 0)
                        {
                            continue;                          // ignoring emty text nodes
                        }
                        if (this.XmlSpace == XmlSpace.Preserve)
                        {
                            this.currentInfo.NodeType = XmlNodeType.SignificantWhitespace;
                        }
                        break;
                    }
                }
                else
                {
                    Debug.Assert(this.processor.ExecutionDone);
                    this.state = ReadState.EndOfFile;
                    Reset();
                }

                return(this.haveRecord);
            }
        }
Esempio n. 8
0
        private int ReadTextNodes()
        {
            bool textPreserveWS = _reader.XmlSpace == XmlSpace.Preserve;
            bool textIsWhite    = true;
            int  curTextNode    = 0;

            do
            {
                switch (_reader.NodeType)
                {
                case XmlNodeType.Text:
                // XLinq reports WS nodes as Text so we need to analyze them here
                case XmlNodeType.CDATA:
                    if (textIsWhite && !XmlCharType.IsOnlyWhitespace(_reader.Value))
                    {
                        textIsWhite = false;
                    }
                    goto case XmlNodeType.SignificantWhitespace;

                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    ExtendRecordBuffer(curTextNode);
                    FillupTextRecord(ref _records[curTextNode]);
                    _reader.Read();
                    curTextNode++;
                    break;

                case XmlNodeType.EntityReference:
                    string local = _reader.LocalName;
                    if (local.Length > 0 && (
                            local[0] == '#' ||
                            local == "lt" || local == "gt" || local == "quot" || local == "apos"
                            ))
                    {
                        // Special treatment for character and built-in entities
                        ExtendRecordBuffer(curTextNode);
                        FillupCharacterEntityRecord(ref _records[curTextNode]);
                        if (textIsWhite && !XmlCharType.IsOnlyWhitespace(_records[curTextNode].value))
                        {
                            textIsWhite = false;
                        }
                        curTextNode++;
                    }
                    else
                    {
                        _reader.ResolveEntity();
                        _reader.Read();
                    }
                    break;

                case XmlNodeType.EndEntity:
                    _reader.Read();
                    break;

                default:
                    _nodeType = (
                        !textIsWhite ? XmlNodeType.Text :
                        textPreserveWS ? XmlNodeType.SignificantWhitespace :
                        /*default:    */ XmlNodeType.Whitespace
                        );
                    return(curTextNode);
                }
            } while (true);
        }
Esempio n. 9
0
 public bool ParseReaderNode()
 {
     if (_reader.Depth > _markupDepth)
     {
         if (_processMarkup)
         {
             ProcessAppInfoDocMarkup(false);
         }
         return(true);
     }
     else if (_reader.NodeType == XmlNodeType.Element)
     {
         if (_builder.ProcessElement(_reader.Prefix, _reader.LocalName, _reader.NamespaceURI))
         {
             _namespaceManager.PushScope();
             if (_reader.MoveToFirstAttribute())
             {
                 do
                 {
                     _builder.ProcessAttribute(_reader.Prefix, _reader.LocalName, _reader.NamespaceURI, _reader.Value);
                     if (Ref.Equal(_reader.NamespaceURI, _schemaNames.NsXmlNs) && _isProcessNamespaces)
                     {
                         _namespaceManager.AddNamespace(_reader.Prefix.Length == 0 ? string.Empty : _reader.LocalName, _reader.Value);
                     }
                 }while (_reader.MoveToNextAttribute());
                 _reader.MoveToElement(); // get back to the element
             }
             _builder.StartChildren();
             if (_reader.IsEmptyElement)
             {
                 _namespaceManager.PopScope();
                 _builder.EndChildren();
                 if (_reader.Depth == _schemaXmlDepth)
                 {
                     return(false); // done
                 }
             }
             else if (!_builder.IsContentParsed())
             { //AppInfo and Documentation
                 _markupDepth   = _reader.Depth;
                 _processMarkup = true;
                 if (_annotationNSManager == null)
                 {
                     _annotationNSManager = new XmlNamespaceManager(_nameTable);
                     _xmlns = _nameTable.Add("xmlns");
                 }
                 ProcessAppInfoDocMarkup(true);
             }
         }
         else if (!_reader.IsEmptyElement)
         {                           //UnsupportedElement in that context
             _markupDepth   = _reader.Depth;
             _processMarkup = false; //Hack to not process unsupported elements
         }
     }
     else if (_reader.NodeType == XmlNodeType.Text)
     { //Check for whitespace
         if (!_xmlCharType.IsOnlyWhitespace(_reader.Value))
         {
             _builder.ProcessCData(_reader.Value);
         }
     }
     else if (_reader.NodeType == XmlNodeType.EntityReference ||
              _reader.NodeType == XmlNodeType.SignificantWhitespace ||
              _reader.NodeType == XmlNodeType.CDATA)
     {
         _builder.ProcessCData(_reader.Value);
     }
     else if (_reader.NodeType == XmlNodeType.EndElement)
     {
         if (_reader.Depth == _markupDepth)
         {
             if (_processMarkup)
             {
                 Debug.Assert(_parentNode != null);
                 XmlNodeList list   = _parentNode.ChildNodes;
                 XmlNode[]   markup = new XmlNode[list.Count];
                 for (int i = 0; i < list.Count; i++)
                 {
                     markup[i] = list[i];
                 }
                 _builder.ProcessMarkup(markup);
                 _namespaceManager.PopScope();
                 _builder.EndChildren();
             }
             _markupDepth = int.MaxValue;
         }
         else
         {
             _namespaceManager.PopScope();
             _builder.EndChildren();
         }
         if (_reader.Depth == _schemaXmlDepth)
         {
             return(false); // done
         }
     }
     return(true);
 }
Esempio n. 10
0
        internal int AddStringQuery(string xpathQuery)
        {
            string modifiedQuery = XmlCharType.IsOnlyWhitespace(xpathQuery) ? xpathQuery : "string(" + xpathQuery + ")";

            return(AddQuery(modifiedQuery));
        }