internal bool FindPrefix(string nspace, out string prefix) { Debug.Assert(nspace != null); for (int i = _elementScopesStack.Length - 1; 0 <= i; i--) { Debug.Assert(_elementScopesStack[i] is OutputScope); OutputScope elementScope = (OutputScope)_elementScopesStack[i]; string pfx = null; if (elementScope.FindPrefix(nspace, out pfx)) { string testNspace = ResolveNamespace(pfx); if (testNspace != null && Ref.Equal(testNspace, nspace)) { prefix = pfx; return(true); } else { break; } } } prefix = null; return(false); }
private void EndElement() { Debug.Assert(_attributeCount == 0); OutputScope elementScope = _scopeManager.CurrentElementScope; _currentInfo !.NodeType = XmlNodeType.EndElement; _currentInfo.Prefix = elementScope.Prefix; _currentInfo.LocalName = elementScope.Name; _currentInfo.NamespaceURI = elementScope.Namespace; _currentInfo.Depth = _recordDepth; }
internal void PopScope() { OutputScope elementScope = (OutputScope)_elementScopesStack.Pop(); Debug.Assert(elementScope != null); // We adding rootElementScope to garantee this for (NamespaceDecl scope = elementScope.Scopes; scope != null; scope = scope.Next) { _defaultNS = scope.PrevDefaultNsUri; } }
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); }
private void FixupElement() { Debug.Assert(_mainNode.NodeType == XmlNodeType.Element); if (Ref.Equal(_mainNode.NamespaceURI, _atoms.Empty)) { _mainNode.Prefix = _atoms.Empty; } if (Ref.Equal(_mainNode.Prefix, _atoms.Empty)) { if (Ref.Equal(_mainNode.NamespaceURI, _scopeManager.DefaultNamespace)) { // Main Node is OK } else { DeclareNamespace(_mainNode.NamespaceURI, _mainNode.Prefix); } } else { bool thisScope = false; string?nspace = _scopeManager.ResolveNamespace(_mainNode.Prefix, out thisScope); if (nspace != null) { if (!Ref.Equal(_mainNode.NamespaceURI, nspace)) { if (thisScope) { // Prefix conflict _mainNode.Prefix = GetPrefixForNamespace(_mainNode.NamespaceURI); } else { DeclareNamespace(_mainNode.NamespaceURI, _mainNode.Prefix); } } } else { DeclareNamespace(_mainNode.NamespaceURI, _mainNode.Prefix); } } OutputScope elementScope = _scopeManager.CurrentElementScope; elementScope.Prefix = _mainNode.Prefix; }
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; }
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)_elementScopesStack.Push(); if (elementScope == null) { elementScope = new OutputScope(); _elementScopesStack.AddToTop(elementScope); } Debug.Assert(elementScope != null); elementScope.Init(name, nspace, prefix, parentScope.Space, parentScope.Lang, parentScope.Mixed); }
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 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); } }
internal OutputScopeManager(XmlNameTable nameTable, OutKeywords atoms) { Debug.Assert(nameTable != null); Debug.Assert(atoms != null); _elementScopesStack = new HWStack(STACK_INCREMENT); _nameTable = nameTable; _atoms = atoms; _defaultNS = _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)_elementScopesStack.Push(); if (rootElementScope == null) { rootElementScope = new OutputScope(); _elementScopesStack.AddToTop(rootElementScope); } rootElementScope.Init(string.Empty, string.Empty, string.Empty, /*space:*/ XmlSpace.None, /*lang:*/ string.Empty, /*mixed:*/ false); }
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); } } } }
internal string ResolveNamespace(string prefix, out bool thisScope) { Debug.Assert(prefix != null); thisScope = true; if (prefix == null || prefix.Length == 0) { return(_defaultNS); } else { if (Ref.Equal(prefix, _atoms.Xml)) { return(_atoms.XmlNamespace); } else if (Ref.Equal(prefix, _atoms.Xmlns)) { return(_atoms.XmlnsNamespace); } for (int i = _elementScopesStack.Length - 1; i >= 0; i--) { Debug.Assert(_elementScopesStack[i] is OutputScope); OutputScope elementScope = (OutputScope)_elementScopesStack[i]; string nspace = elementScope.ResolveAtom(prefix); if (nspace != null) { thisScope = (i == _elementScopesStack.Length - 1); return(nspace); } } } return(null); }