示例#1
0
        internal bool FindPrefix(string nspace, out string prefix)
        {
            Debug.Assert(nspace != null);
            for (int i = this.elementScopesStack.Length - 1; 0 <= i; i--)
            {
                Debug.Assert(this.elementScopesStack[i] is OutputScope);

                OutputScope elementScope = (OutputScope)this.elementScopesStack[i];
                string      pfx          = null;
                if (elementScope.FindPrefix(nspace, out pfx))
                {
                    string testNspace = ResolveNamespace(pfx);
                    if (testNspace != null && Keywords.Equals(testNspace, nspace))
                    {
                        prefix = pfx;
                        return(true);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            prefix = null;
            return(false);
        }
        private void EndElement()
        {
            Debug.Assert(this.attributeCount == 0);
            OutputScope elementScope = this.scopeManager.CurrentElementScope;

            NodeType     = XmlNodeType.EndElement;
            Prefix       = elementScope.Prefix;
            LocalName    = elementScope.Name;
            NamespaceURI = elementScope.Namespace;
            Depth        = this.recordDepth;
        }
示例#3
0
        internal void PopScope()
        {
            OutputScope elementScope = (OutputScope)this.elementScopesStack.Pop();

            Debug.Assert(elementScope != null); // We adding rootElementScope to garantee this

            for (NamespaceDecl scope = elementScope.Scopes; scope != null; scope = scope.Next)
            {
                Debug.WriteLine("Popping namespace scope : " + scope.Prefix + " : " + scope.Uri);
                this.defaultNS = scope.PrevDefaultNsUri;
            }
        }
        private void FixupElement()
        {
            Debug.Assert(this.mainNode.NodeType == XmlNodeType.Element);

            if (Keywords.Equals(this.mainNode.NamespaceURI, this.atoms.Empty))
            {
                this.mainNode.Prefix = this.atoms.Empty;
            }

            if (Keywords.Equals(this.mainNode.Prefix, this.atoms.Empty))
            {
                if (Keywords.Equals(this.mainNode.NamespaceURI, this.scopeManager.DefaultNamespace))
                {
                    // Main Node is OK
                }
                else
                {
                    DeclareNamespace(this.mainNode.NamespaceURI, this.mainNode.Prefix);
                }
            }
            else
            {
                bool   thisScope = false;
                string nspace    = this.scopeManager.ResolveNamespace(this.mainNode.Prefix, out thisScope);
                if (nspace != null)
                {
                    if (!Keywords.Equals(this.mainNode.NamespaceURI, nspace))
                    {
                        if (thisScope)      // Prefix conflict
                        {
                            this.mainNode.Prefix = GetPrefixForNamespace(this.mainNode.NamespaceURI);
                        }
                        else
                        {
                            DeclareNamespace(this.mainNode.NamespaceURI, this.mainNode.Prefix);
                        }
                    }
                }
                else
                {
                    DeclareNamespace(this.mainNode.NamespaceURI, this.mainNode.Prefix);
                }
            }

            OutputScope elementScope = this.scopeManager.CurrentElementScope;

            elementScope.Prefix = this.mainNode.Prefix;
        }
示例#5
0
        internal void PushScope(string name, string nspace, string prefix)
        {
            Debug.Assert(name != null);
            Debug.Assert(nspace != null);
            Debug.Assert(prefix != null);
            OutputScope parentScope  = CurrentElementScope;
            OutputScope elementScope = (OutputScope)this.elementScopesStack.Push();

            if (elementScope == null)
            {
                elementScope = new OutputScope();
                this.elementScopesStack.AddToTop(elementScope);
            }

            Debug.Assert(elementScope != null);
            elementScope.Init(name, nspace, prefix, parentScope.Space, parentScope.Lang, parentScope.Mixed);
        }
示例#6
0
        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);
            }
        }
示例#7
0
        internal OutputScopeManager(XmlNameTable nameTable, OutKeywords atoms)
        {
            Debug.Assert(nameTable != null);
            Debug.Assert(atoms != null);

            this.elementScopesStack = new HWStack(STACK_INCREMENT);
            this.nameTable          = nameTable;
            this.atoms     = atoms;
            this.defaultNS = this.atoms.Empty;

            // We always adding rootElementScope to garantee that CurrentElementScope != null
            // This context is active between PI and first element for example
            OutputScope rootElementScope = (OutputScope)this.elementScopesStack.Push();

            if (rootElementScope == null)
            {
                rootElementScope = new OutputScope();
                this.elementScopesStack.AddToTop(rootElementScope);
            }
            rootElementScope.Init(string.Empty, string.Empty, string.Empty, /*space:*/ XmlSpace.None, /*lang:*/ String.Empty, /*mixed:*/ false);
        }
        private void AnalyzeSpaceLang()
        {
            Debug.Assert(this.mainNode.NodeType == XmlNodeType.Element);

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

                if (Keywords.Equals(info.Prefix, this.atoms.Xml))
                {
                    OutputScope scope = this.scopeManager.CurrentElementScope;

                    if (Keywords.Equals(info.LocalName, this.atoms.Lang))
                    {
                        scope.Lang = info.Value;
                    }
                    else if (Keywords.Equals(info.LocalName, this.atoms.Space))
                    {
                        scope.Space = TranslateXmlSpace(info.Value);
                    }
                }
            }
        }
示例#9
0
        internal string ResolveNamespace(string prefix, out bool thisScope)
        {
            Debug.Assert(prefix != null);
            thisScope = true;

            if (prefix == null || prefix.Length == 0)
            {
                return(this.defaultNS);
            }
            else
            {
                if (Keywords.Equals(prefix, this.atoms.Xml))
                {
                    return(this.atoms.XmlNamespace);
                }
                else if (Keywords.Equals(prefix, this.atoms.Xmlns))
                {
                    return(this.atoms.XmlnsNamespace);
                }

                for (int i = this.elementScopesStack.Length - 1; i >= 0; i--)
                {
                    Debug.Assert(this.elementScopesStack[i] is OutputScope);
                    OutputScope elementScope = (OutputScope)this.elementScopesStack[i];

                    string nspace = elementScope.ResolveAtom(prefix);
                    if (nspace != null)
                    {
                        thisScope = (i == this.elementScopesStack.Length - 1);
                        return(nspace);
                    }
                }
            }

            return(null);
        }