Пример #1
0
 internal BuilderInfo Clone()
 {
     BuilderInfo info = new BuilderInfo();
     info.Initialize(this);
     Debug.Assert(info.NodeType != XmlNodeType.Text || XmlCharType.Instance.IsOnlyWhitespace(info.Value));
     return info;
 }
Пример #2
0
        internal void Initialize(BuilderInfo src) {
            this.prefix        = src.Prefix;
            this.localName     = src.LocalName;
            this.namespaceURI  = src.NamespaceURI;
            this.name          = null;
            this.depth         = src.Depth;
            this.nodeType      = src.NodeType;
            this.htmlProps     = src.htmlProps;
            this.htmlAttrProps = src.htmlAttrProps;

            this.TextInfoCount = 0;
            EnsureTextInfoSize(src.TextInfoCount);
            src.TextInfo.CopyTo(this.TextInfo, 0);
            this.TextInfoCount = src.TextInfoCount;
        }
        void WriteEndElement(RecordBuilder record)
        {
            BuilderInfo      node      = record.MainNode;
            HtmlElementProps htmlProps = record.Manager.CurrentElementScope.HtmlElementProps;

            if (htmlProps != null && htmlProps.Empty)
            {
                return;
            }

            Indent(record);
            Write(s_LessThanSlash);
            WriteName(record.MainNode.Prefix, record.MainNode.LocalName);
            Write(s_GreaterThan);
        }
        internal void Initialize(BuilderInfo src)
        {
            this.prefix        = src.Prefix;
            this.localName     = src.LocalName;
            this.namespaceURI  = src.NamespaceURI;
            this.name          = null;
            this.depth         = src.Depth;
            this.nodeType      = src.NodeType;
            this.htmlProps     = src.htmlProps;
            this.htmlAttrProps = src.htmlAttrProps;

            this.TextInfoCount = 0;
            EnsureTextInfoSize(src.TextInfoCount);
            src.TextInfo.CopyTo(this.TextInfo, 0);
            this.TextInfoCount = src.TextInfoCount;
        }
Пример #5
0
        private void WriteProcessingInstruction(BuilderInfo node)
        {
            Write(s_LessThanQuestion);
            WriteName(node.Prefix, node.LocalName);
            Write(s_Space);
            Write(node.Value);

            if (_isHtmlOutput)
            {
                Write(s_GreaterThan);
            }
            else
            {
                Write(s_QuestionGreaterThan);
            }
        }
Пример #6
0
 private void WriteTextNode(BuilderInfo node)
 {
     for (int i = 0; i < node.TextInfoCount; i++)
     {
         string?text = node.TextInfo[i];
         if (text == null)
         { // disableEscaping marker
             i++;
             Debug.Assert(i < node.TextInfoCount, "disableEscaping marker can't be last TextInfo record");
             Write(node.TextInfo[i]);
         }
         else
         {
             WriteWithReplace(text, s_TextValueFind, s_TextValueReplace);
         }
     }
 }
Пример #7
0
        private void OutputCachedRecords()
        {
            if (_outputCache == null)
            {
                return;
            }

            for (int record = 0; record < _outputCache.Count; record++)
            {
                Debug.Assert(_outputCache[record] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)_outputCache[record] !;

                OutputRecord(info);
            }

            _outputCache = null;
        }
Пример #8
0
        private void ResetRecord(int state)
        {
            Debug.Assert(_recordState == NoRecord || _recordState == SomeRecord);

            if ((state & StateMachine.BeginRecord) != 0)
            {
                _attributeCount = 0;
                _namespaceCount = 0;
                _currentInfo    = _mainNode;

                _currentInfo.Initialize(_atoms.Empty, _atoms.Empty, _atoms.Empty);
                _currentInfo.NodeType      = XmlNodeType.None;
                _currentInfo.IsEmptyTag    = false;
                _currentInfo.htmlProps     = null;
                _currentInfo.htmlAttrProps = null;
            }
        }
Пример #9
0
        private void FixupAttributes(int attributeCount)
        {
            for (int attr = 0; attr < attributeCount; attr++)
            {
                Debug.Assert(this.attributeList[attr] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)this.attributeList[attr];


                if (Keywords.Equals(info.NamespaceURI, this.atoms.Empty))
                {
                    info.Prefix = this.atoms.Empty;
                }
                else
                {
                    if (Keywords.Equals(info.Prefix, this.atoms.Empty))
                    {
                        info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                    }
                    else
                    {
                        bool   thisScope = false;
                        string nspace    = this.scopeManager.ResolveNamespace(info.Prefix, out thisScope);
                        if (nspace != null)
                        {
                            if (!Keywords.Equals(info.NamespaceURI, nspace))
                            {
                                if (thisScope)  // prefix conflict
                                {
                                    info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                                }
                                else
                                {
                                    DeclareNamespace(info.NamespaceURI, info.Prefix);
                                }
                            }
                        }
                        else
                        {
                            DeclareNamespace(info.NamespaceURI, info.Prefix);
                        }
                    }
                }
            }
        }
Пример #10
0
        private void FixupAttributes(int attributeCount)
        {
            for (int attr = 0; attr < attributeCount; attr++)
            {
                Debug.Assert(_attributeList[attr] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)_attributeList[attr] !;


                if (Ref.Equal(info.NamespaceURI, _atoms.Empty))
                {
                    info.Prefix = _atoms.Empty;
                }
                else
                {
                    if (Ref.Equal(info.Prefix, _atoms.Empty))
                    {
                        info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                    }
                    else
                    {
                        bool   thisScope = false;
                        string?nspace    = _scopeManager.ResolveNamespace(info.Prefix, out thisScope);
                        if (nspace != null)
                        {
                            if (!Ref.Equal(info.NamespaceURI, nspace))
                            {
                                if (thisScope)
                                { // prefix conflict
                                    info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                                }
                                else
                                {
                                    DeclareNamespace(info.NamespaceURI, info.Prefix);
                                }
                            }
                        }
                        else
                        {
                            DeclareNamespace(info.NamespaceURI, info.Prefix);
                        }
                    }
                }
            }
        }
Пример #11
0
        //
        // RecordOutput interface method implementation
        //

        public Processor.OutputResult RecordDone(RecordBuilder record)
        {
            BuilderInfo mainNode = record.MainNode;

            switch (mainNode.NodeType)
            {
            case XmlNodeType.Text:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                _writer.Write(mainNode.Value);
                break;

            default:
                break;
            }

            record.Reset();
            return(Processor.OutputResult.Continue);
        }
Пример #12
0
        private void BeginNamespace(string name, string nspace)
        {
            bool thisScope = false;

            if (Ref.Equal(name, _atoms.Empty))
            {
                if (Ref.Equal(nspace, _scopeManager.DefaultNamespace))
                {
                    // Main Node is OK
                }
                else if (Ref.Equal(_mainNode.NamespaceURI, _atoms.Empty))
                {
                    // http://www.w3.org/1999/11/REC-xslt-19991116-errata/ E25
                    // Should throw an error but ingnoring it in Everett.
                    // Would be a breaking change
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            else
            {
                string nspaceDeclared = _scopeManager.ResolveNamespace(name, out thisScope);
                if (nspaceDeclared != null)
                {
                    if (!Ref.Equal(nspace, nspaceDeclared))
                    {
                        if (!thisScope)
                        {
                            DeclareNamespace(nspace, name);
                        }
                    }
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            _currentInfo          = _dummy;
            _currentInfo.NodeType = XmlNodeType.Attribute;
        }
Пример #13
0
        private void BeginAttribute(string prefix, string name, string nspace, object?htmlAttrProps, bool search)
        {
            int attrib = FindAttribute(name, nspace, ref prefix);

            if (attrib == -1)
            {
                attrib = NewAttribute();
            }

            Debug.Assert(_attributeList[attrib] != null && _attributeList[attrib] is BuilderInfo);

            BuilderInfo attribute = (BuilderInfo)_attributeList[attrib] !;

            attribute.Initialize(prefix, name, nspace);
            attribute.Depth         = _recordDepth;
            attribute.NodeType      = XmlNodeType.Attribute;
            attribute.htmlAttrProps = htmlAttrProps as HtmlAttributeProps;
            attribute.search        = search;
            _currentInfo            = attribute;
        }
Пример #14
0
        private void WriteTextNode(RecordBuilder record)
        {
            BuilderInfo mainNode = record.MainNode;
            OutputScope scope    = record.Manager.CurrentElementScope;

            scope.Mixed = true;

            if (scope.HtmlElementProps != null && scope.HtmlElementProps.NoEntities)
            {
                // script or stile
                Write(mainNode.Value);
            }
            else if (scope.ToCData)
            {
                WriteCDataSection(mainNode.Value);
            }
            else
            {
                WriteTextNode(mainNode);
            }
        }
Пример #15
0
        private void BeginNamespace(string name, string nspace)
        {
            bool thisScope = false;

            if (Keywords.Equals(name, this.atoms.Empty))
            {
                if (Keywords.Equals(nspace, this.scopeManager.DefaultNamespace))
                {
                    // Main Node is OK
                }
                else if (Keywords.Equals(this.mainNode.NamespaceURI, this.atoms.Empty))
                {
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            else
            {
                string nspaceDeclared = this.scopeManager.ResolveNamespace(name, out thisScope);
                if (nspaceDeclared != null)
                {
                    if (!Keywords.Equals(nspace, nspaceDeclared))
                    {
                        if (!thisScope)
                        {
                            DeclareNamespace(nspace, name);
                        }
                    }
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            this.currentInfo     = dummy;
            currentInfo.NodeType = XmlNodeType.Attribute;
        }
Пример #16
0
        private void DeclareNamespace(string nspace, string prefix)
        {
            int index = NewNamespace();

            Debug.Assert(_namespaceList[index] != null && _namespaceList[index] is BuilderInfo);

            BuilderInfo ns = (BuilderInfo)_namespaceList[index] !;

            if (prefix == _atoms.Empty)
            {
                ns.Initialize(_atoms.Empty, _atoms.Xmlns, _atoms.XmlnsNamespace);
            }
            else
            {
                ns.Initialize(_atoms.Xmlns, prefix, _atoms.XmlnsNamespace);
            }
            ns.Depth    = _recordDepth;
            ns.NodeType = XmlNodeType.Attribute;
            ns.Value    = nspace;

            _scopeManager.PushNamespace(prefix, nspace);
        }
Пример #17
0
        private bool FindAttribute(String name, out int attrIndex)
        {
            if (name == null)
            {
                name = string.Empty;
            }

            for (int index = 0; index < this.attributeCount; index++)
            {
                Debug.Assert(this.attributeList[index] is BuilderInfo);

                BuilderInfo attribute = (BuilderInfo)this.attributeList[index];
                if (attribute.Name == name)
                {
                    attrIndex = index;
                    return(true);
                }
            }

            attrIndex = -1;
            return(false);
        }
Пример #18
0
        public override bool ReadAttributeValue()
        {
            if (ReadState != ReadState.Interactive || NodeType != XmlNodeType.Attribute)
            {
                return(false);
            }

            if (this.attributeValue == null)
            {
                this.attributeValue          = new BuilderInfo();
                this.attributeValue.NodeType = XmlNodeType.Text;
            }
            if (this.currentInfo == this.attributeValue)
            {
                return(false);
            }

            this.attributeValue.Value = this.currentInfo.Value;
            this.attributeValue.Depth = this.currentInfo.Depth + 1;
            this.currentInfo          = this.attributeValue;

            return(true);
        }
Пример #19
0
        private void AnalyzeSpaceLang()
        {
            Debug.Assert(_mainNode.NodeType == XmlNodeType.Element);

            for (int attr = 0; attr < _attributeCount; attr++)
            {
                Debug.Assert(_attributeList[attr] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)_attributeList[attr] !;

                if (Ref.Equal(info.Prefix, _atoms.Xml))
                {
                    OutputScope scope = _scopeManager.CurrentElementScope;

                    if (Ref.Equal(info.LocalName, _atoms.Lang))
                    {
                        scope.Lang = info.Value;
                    }
                    else if (Ref.Equal(info.LocalName, _atoms.Space))
                    {
                        scope.Space = TranslateXmlSpace(info.Value);
                    }
                }
            }
        }
Пример #20
0
        //
        // Implementation internals
        //

        private void SetMainNode()
        {
            _currentIndex = -1;
            _currentInfo  = _mainNode;
        }
Пример #21
0
        //
        // Particular outputs
        //
        private void WriteStartElement(RecordBuilder record)
        {
            Debug.Assert(record.MainNode.NodeType == XmlNodeType.Element);
            BuilderInfo      mainNode  = record.MainNode;
            HtmlElementProps?htmlProps = null;

            if (_isHtmlOutput)
            {
                if (mainNode.Prefix.Length == 0)
                {
                    htmlProps = mainNode.htmlProps;
                    if (htmlProps == null && mainNode.search)
                    {
                        htmlProps = HtmlElementProps.GetProps(mainNode.LocalName);
                    }
                    record.Manager.CurrentElementScope.HtmlElementProps = htmlProps;
                    mainNode.IsEmptyTag = false;
                }
            }
            else if (_isXmlOutput)
            {
                if (mainNode.Depth == 0)
                {
                    if (
                        _secondRoot && (
                            _output.DoctypeSystem != null ||
                            _output.Standalone
                            )
                        )
                    {
                        throw XsltException.Create(SR.Xslt_MultipleRoots);
                    }
                    _secondRoot = true;
                }
            }

            if (_outputDoctype)
            {
                WriteDoctype(mainNode);
                _outputDoctype = false;
            }

            if (_cdataElements != null && _cdataElements.Contains(new XmlQualifiedName(mainNode.LocalName, mainNode.NamespaceURI)) && _isXmlOutput)
            {
                record.Manager.CurrentElementScope.ToCData = true;
            }

            Indent(record);
            Write(s_LessThan);
            WriteName(mainNode.Prefix, mainNode.LocalName);

            WriteAttributes(record.AttributeList, record.AttributeCount, htmlProps);


            if (mainNode.IsEmptyTag)
            {
                Debug.Assert(!_isHtmlOutput || mainNode.Prefix != null, "Html can't have abbreviated elements");
                Write(s_SlashGreaterThan);
            }
            else
            {
                Write(s_GreaterThan);
            }

            if (htmlProps != null && htmlProps.Head)
            {
                mainNode.Depth++;
                Indent(record);
                mainNode.Depth--;
                Write("<META http-equiv=\"Content-Type\" content=\"");
                Write(_output.MediaType);
                Write("; charset=");
                Write(this.encoding !.WebName);
                Write("\">");
            }
        }
Пример #22
0
        private void SetAttribute(int attrib)
        {
            Debug.Assert(0 <= attrib && attrib < _attributeCount);
            Debug.Assert(0 <= attrib && attrib < _attributeList.Count);
            Debug.Assert(_attributeList[attrib] is BuilderInfo);

            _currentIndex = attrib;
            _currentInfo = (BuilderInfo)_attributeList[attrib];
        }
Пример #23
0
 private void Reset()
 {
     _currentIndex = -1;
     _currentInfo = s_DefaultInfo;
     _mainNode = s_DefaultInfo;
     _manager = null;
 }
 void WriteDoctype(BuilderInfo mainNode) {
     Debug.Assert(this.outputDoctype == true, "It supposed to check this condition before actual call");
     Debug.Assert(this.output.DoctypeSystem != null || (this.isHtmlOutput && this.output.DoctypePublic != null), "We set outputDoctype == true only if");
     Indent(0);
     Write(s_DocType);
     if (this.isXmlOutput) {
         WriteName(mainNode.Prefix, mainNode.LocalName);
     }
     else {
         WriteName(string.Empty, "html");
     }
     Write(s_Space);
     if (output.DoctypePublic != null) {
         Write(s_Public);
         Write(s_Quote);
         Write(output.DoctypePublic);
         Write(s_QuoteSpace);
     }
     else {
         Write(s_System);
     }
     if (output.DoctypeSystem != null) {
         Write(s_Quote);
         Write(output.DoctypeSystem);
         Write(s_Quote);
     }
     Write(s_GreaterThan);
 }
        void WriteProcessingInstruction(BuilderInfo node) {
            Write(s_LessThanQuestion);
            WriteName(node.Prefix, node.LocalName);
            Write(s_Space);
            Write(node.Value);

            if(this.isHtmlOutput) {
                Write(s_GreaterThan);
            }
            else {
                Write(s_QuestionGreaterThan);
            }
        }
Пример #26
0
        private void SetAttribute(int attrib) {
            Debug.Assert(0 <= attrib && attrib < this.attributeCount);
            Debug.Assert(0 <= attrib && attrib < this.attributeList.Count);
            Debug.Assert(this.attributeList[attrib] is BuilderInfo);

            this.currentIndex = attrib;
            this.currentInfo  = (BuilderInfo) this.attributeList[attrib];
        }
Пример #27
0
        //
        // Implementation internals
        //

        private void SetMainNode() {
            this.currentIndex   = -1;
            this.currentInfo    = this.mainNode;
        }
Пример #28
0
        //
        // Implementation internals
        //

        private void SetMainNode()
        {
            _currentIndex = -1;
            _currentInfo = _mainNode;
        }
Пример #29
0
        public override string GetAttribute(int i)
        {
            BuilderInfo attribute = GetBuilderInfo(i);

            return(attribute.Value);
        }
 private void BeginNamespace(string name, string nspace) {
     bool thisScope = false;
     if (Keywords.Equals(name, this.atoms.Empty)) {
         if (Keywords.Equals(nspace, this.scopeManager.DefaultNamespace)) {
             // Main Node is OK
         }
         else if (Keywords.Equals(this.mainNode.NamespaceURI, this.atoms.Empty)) {
         }
         else {
             DeclareNamespace(nspace, name);
         }
     }
     else {
         string nspaceDeclared = this.scopeManager.ResolveNamespace(name, out thisScope);
         if (nspaceDeclared != null) {
             if (! Keywords.Equals(nspace, nspaceDeclared)) {
                 if(!thisScope) {
                     DeclareNamespace(nspace, name);
                 }
             }
         }
         else {
              DeclareNamespace(nspace, name);
         }
     }
     this.currentInfo = dummy;
     currentInfo.NodeType = XmlNodeType.Attribute;
 }
        private void OutputRecord(BuilderInfo node) {
            if(this.outputXmlDecl) {
                WriteXmlDeclaration();
            }

            Indent(0); // we can have only top level stuff here

            switch (node.NodeType) {
            case XmlNodeType.Element:
                Debug.Fail("Should never get here");
                break;
            case XmlNodeType.Text:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                WriteTextNode(node);
                break;
            case XmlNodeType.CDATA:
                Debug.Fail("Should never get here");
                break;
            case XmlNodeType.EntityReference:
                Write(s_Ampersand);
                WriteName(node.Prefix, node.LocalName);
                Write(s_Semicolon);
                break;
            case XmlNodeType.ProcessingInstruction:
                WriteProcessingInstruction(node);
                break;
            case XmlNodeType.Comment:
                Write(s_CommentBegin);
                Write(node.Value);
                Write(s_CommentEnd);
                break;
            case XmlNodeType.Document:
                break;
            case XmlNodeType.DocumentType:
                Write(node.Value);
                break;
            case XmlNodeType.EndElement:
                Debug.Fail("Should never get here");
                break;
            default:
                break;
            }
        }
 private bool DecideDefaultOutput(BuilderInfo node) {
     XsltOutput.OutputMethod method = XsltOutput.OutputMethod.Xml;
     switch (node.NodeType) {
     case XmlNodeType.Element:
         if (node.NamespaceURI.Length == 0 && String.Compare("html", node.LocalName, StringComparison.OrdinalIgnoreCase) == 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;
 }
Пример #33
0
 private void Reset() {
     this.currentIndex = -1;
     this.currentInfo  = s_DefaultInfo;
     this.mainNode     = s_DefaultInfo;
     this.manager      = null;
 }
Пример #34
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);
        }
Пример #35
0
        private void BeginAttribute(string prefix, string name, string nspace, Object htmlAttrProps, bool search) {
            int attrib = FindAttribute(name, nspace, ref prefix);

            if (attrib == -1) {
                attrib = NewAttribute();
            }

            Debug.Assert(this.attributeList[attrib] != null && this.attributeList[attrib] is BuilderInfo);

            BuilderInfo attribute = (BuilderInfo) this.attributeList[attrib];
            attribute.Initialize(prefix, name, nspace);
            attribute.Depth = this.recordDepth;
            attribute.NodeType = XmlNodeType.Attribute;
            attribute.htmlAttrProps = htmlAttrProps as HtmlAttributeProps;
            attribute.search = search;
            this.currentInfo  = attribute;
        }
 void WriteTextNode(BuilderInfo node) {
     for (int i = 0; i < node.TextInfoCount; i ++) {
         string text = node.TextInfo[i];
         if (text == null) { // disableEscaping marker
             i++;
             Debug.Assert(i < node.TextInfoCount, "disableEscaping marker can't be last TextInfo record");
             Write(node.TextInfo[i]);
         } else {
             WriteWithReplace(text, s_TextValueFind, s_TextValueReplace);
         }
     }
 }
Пример #37
0
 private void BeginNamespace(string name, string nspace) {
     bool thisScope = false;
     if (Ref.Equal(name, this.atoms.Empty)) {
         if (Ref.Equal(nspace, this.scopeManager.DefaultNamespace)) {
             // Main Node is OK
         }
         else if (Ref.Equal(this.mainNode.NamespaceURI, this.atoms.Empty)) {
             // http://www.w3.org/1999/11/REC-xslt-19991116-errata/ E25 
             // Should throw an error but ingnoring it in Everett. 
             // Would be a breaking change
         }
         else {
             DeclareNamespace(nspace, name);
         }
     }
     else {
         string nspaceDeclared = this.scopeManager.ResolveNamespace(name, out thisScope);
         if (nspaceDeclared != null) {
             if (! Ref.Equal(nspace, nspaceDeclared)) {
                 if(!thisScope) {
                     DeclareNamespace(nspace, name);
                 }
             }
         }
         else {
              DeclareNamespace(nspace, name);
         }
     }
     this.currentInfo = dummy;
     currentInfo.NodeType = XmlNodeType.Attribute;
 }
Пример #38
0
        private void ResetRecord(int state) {
            Debug.Assert(this.recordState == NoRecord || this.recordState == SomeRecord);

            if ((state & StateMachine.BeginRecord) != 0) {
                this.attributeCount     = 0;
                this.namespaceCount     = 0;
                this.currentInfo        = this.mainNode;

                this.currentInfo.Initialize(this.atoms.Empty, this.atoms.Empty, this.atoms.Empty);
                this.currentInfo.NodeType      = XmlNodeType.None;
                this.currentInfo.IsEmptyTag    = false;
                this.currentInfo.htmlProps     = null;
                this.currentInfo.htmlAttrProps = null;
            }
        }
Пример #39
0
        // RecordOutput interface method implementation
        //
        public Processor.OutputResult RecordDone(RecordBuilder record)
        {
            BuilderInfo mainNode = record.MainNode;

            switch (mainNode.NodeType)
            {
            case XmlNodeType.Element:
                _writer.WriteStartElement(mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI);

                WriteAttributes(record.AttributeList, record.AttributeCount);

                if (mainNode.IsEmptyTag)
                {
                    _writer.WriteEndElement();
                }
                break;

            case XmlNodeType.Text:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                _writer.WriteString(mainNode.Value);
                break;

            case XmlNodeType.CDATA:
                Debug.Fail("XSLT never gives us CDATA");
                _writer.WriteCData(mainNode.Value);
                break;

            case XmlNodeType.EntityReference:
                _writer.WriteEntityRef(mainNode.LocalName);
                break;

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

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

            case XmlNodeType.Document:
                break;

            case XmlNodeType.DocumentType:
                _writer.WriteRaw(mainNode.Value);
                break;

            case XmlNodeType.EndElement:
                _writer.WriteFullEndElement();
                break;

            case XmlNodeType.None:
            case XmlNodeType.Attribute:
            case XmlNodeType.Entity:
            case XmlNodeType.Notation:
            case XmlNodeType.DocumentFragment:
            case XmlNodeType.EndEntity:
                break;

            default:
                Debug.Fail("Invalid NodeType on output: " + mainNode.NodeType);
                break;
            }

            record.Reset();
            return(Processor.OutputResult.Continue);
        }
Пример #40
0
        public override bool ReadAttributeValue() {
            if (ReadState != ReadState.Interactive || NodeType != XmlNodeType.Attribute) {
                return false;
            }

            if (this.attributeValue == null) {
                this.attributeValue = new BuilderInfo();
                this.attributeValue.NodeType = XmlNodeType.Text;
            }
            if (this.currentInfo == this.attributeValue) {
                return false;
            }

            this.attributeValue.Value = this.currentInfo.Value;
            this.attributeValue.Depth = this.currentInfo.Depth + 1;
            this.currentInfo          = this.attributeValue;

            return true;
        }
Пример #41
0
        //
        // Implementation internals
        //

        private void SetMainNode()
        {
            this.currentIndex = -1;
            this.currentInfo  = this.mainNode;
        }
Пример #42
0
        //
        // RecordOutput interface method implementation
        //

        public Processor.OutputResult RecordDone(RecordBuilder record) {
            this.builder        = record;
            this.mainNode       = record.MainNode;
            this.attributeList  = record.AttributeList;
            this.attributeCount = record.AttributeCount;
            this.manager        = record.Manager;

            this.haveRecord     = true;
            SetMainNode();

            return Processor.OutputResult.Interrupt;
        }
Пример #43
0
        public override bool ReadAttributeValue()
        {
            if (ReadState != ReadState.Interactive || NodeType != XmlNodeType.Attribute)
            {
                return false;
            }

            if (_attributeValue == null)
            {
                _attributeValue = new BuilderInfo();
                _attributeValue.NodeType = XmlNodeType.Text;
            }
            if (_currentInfo == _attributeValue)
            {
                return false;
            }

            _attributeValue.Value = _currentInfo.Value;
            _attributeValue.Depth = _currentInfo.Depth + 1;
            _currentInfo = _attributeValue;

            return true;
        }