public void AddFirst(string prefix, XNamespace ns) { var namespaceDeclaration = new NamespaceResolver.NamespaceDeclaration(); namespaceDeclaration.prefix = prefix; namespaceDeclaration.ns = ns; namespaceDeclaration.scope = this.scope; if (this.declaration == null) { namespaceDeclaration.prev = namespaceDeclaration; } else { namespaceDeclaration.prev = this.declaration.prev; this.declaration.prev = namespaceDeclaration; } this.declaration = namespaceDeclaration; this.rover = null; }
public string GetPrefixOfNamespace(XNamespace ns, bool allowDefaultNamespace) { if (this.rover != null && this.rover.ns == ns && (allowDefaultNamespace || this.rover.prefix.Length > 0)) { return this.rover.prefix; } var prev = this.declaration; if (prev != null) { while (true) { prev = prev.prev; if (prev.ns == ns) { var prev2 = this.declaration.prev; while (prev2 != prev && prev2.prefix != prev.prefix) { prev2 = prev2.prev; } if (prev2 == prev) { if (allowDefaultNamespace) { break; } if (prev.prefix.Length > 0) { return prev.prefix; } } } if (prev == this.declaration) { return null; } } this.rover = prev; return prev.prefix; } return null; }
public void PopScope() { var prev = this.declaration; if (prev != null) { do { prev = prev.prev; if (prev.scope != this.scope) { break; } if (prev == this.declaration) { this.declaration = null; } else { this.declaration.prev = prev.prev; } this.rover = null; } while (prev != this.declaration && this.declaration != null); } this.scope--; }