Beispiel #1
0
        public DomNamespace GetNamespace(string prefix, DomScope scope)
        {
            if (string.IsNullOrEmpty(prefix))
            {
                throw Failure.NullOrEmptyString(nameof(prefix));
            }
            if (prefix == "xmlns")
            {
                return(null);
            }

            string ns;

            if (scope == DomScope.TargetAndAncestors)
            {
                ns = GetNamespaceAncestors(_element, prefix);
            }
            else
            {
                // We don't do descendant search even if was requested
                ns = GetNamespaceCore(_element, prefix);
            }
            if (ns == null)
            {
                return(null);
            }
            return(DomNamespace.Create(ns));
        }
 public override int Compare(DomNamespace x, DomNamespace y)
 {
     if (x is null || y is null)
     {
         return(Comparer <object> .Default.Compare(x, y));
     }
     return(StringComparer.Ordinal.Compare(x.NamespaceUri, y.NamespaceUri));
 }
Beispiel #3
0
 public DomName WithNamespace(DomNamespace value)
 {
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     return(value + LocalName);
 }
 public override bool Equals(DomNamespace x, DomNamespace y)
 {
     if (x is null || y is null)
     {
         return(ReferenceEquals(x, y));
     }
     return(StringComparer.Ordinal.Equals(x.NamespaceUri, y.NamespaceUri));
 }
 public override int GetHashCode(DomNamespace obj)
 {
     if (obj is null)
     {
         return(-1);
     }
     return(StringComparer.Ordinal.GetHashCode(obj.NamespaceUri));
 }
        public static DomElement SetDefaultXmlns(this DomElement self, DomNamespace ns)
        {
            if (self is null)
            {
                throw new ArgumentNullException(nameof(self));
            }

            return(self.Attribute("xmlns", ns));
        }
Beispiel #7
0
 public string RegisterPrefix(DomNamespace ns, string preferredPrefix)
 {
     if (ns is null)
     {
         throw new ArgumentNullException(nameof(ns));
     }
     _element.SetXmlns(preferredPrefix, ns);
     return(preferredPrefix);
 }
 public override int Compare(DomNamespace x, DomNamespace y)
 {
     if (x is null || y is null)
     {
         return(Comparer <object> .Default.Compare(x, y));
     }
     return(string.Compare(
                NormalizeUri(x), NormalizeUri(y), StringComparison.OrdinalIgnoreCase
                ));
 }
Beispiel #9
0
        public static DomName Create(string namespaceUri, string localName)
        {
            DomNamespace nu = DomNamespace.Default;

            if (namespaceUri != null)
            {
                nu = DomNamespace.Create(namespaceUri);
            }
            return(nu + localName);
        }
Beispiel #10
0
        static Exception _TryParse(string text, out DomName result)
        {
            result = null;

            if (string.IsNullOrEmpty(text))
            {
                throw Failure.NullOrEmptyString(nameof(text));
            }

            if (text[0] == '{')
            {
                int num = text.LastIndexOf('}');

                if ((num <= 1) || (num == (text.Length - 1)))
                {
                    return(Failure.NotParsable(nameof(text), typeof(DomName)));
                }

                if (num - 1 == 0)
                {
                    // The default namespace is used (as in '{} expandedName')
                    result = DomNamespace.Default.GetName(text.Trim());
                    return(null);
                }
                else
                {
                    // Some other namespace is used
                    string ns        = text.Substring(1, num - 1);
                    string localName = text.Substring(num + 1).Trim();

                    DomNamespace nu = DomNamespace._TryParse(ns, false);
                    if (nu == null)
                    {
                        return(Failure.NotParsable(nameof(text), typeof(DomName)));
                    }
                    result = nu.GetName(localName);
                    return(null);
                }
            }

            if (!text.Contains(":"))
            {
                result = DomNamespace.Default.GetName(text.Trim());
                return(null);
            }

            return(Failure.NotParsable(nameof(text), typeof(DomName)));
        }
Beispiel #11
0
 public static DomElement SetXmlns(this DomElement self, string prefix, DomNamespace ns)
 {
     if (self is null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     if (ns is null)
     {
         throw new ArgumentNullException(nameof(ns));
     }
     if (string.IsNullOrEmpty(prefix))
     {
         throw new NotImplementedException();
     }
     return(self.Attribute($"xmlns:{prefix}", ns));
 }
            private static string NormalizeUri(DomNamespace ns)
            {
                if (ns == null)
                {
                    return(null);
                }
                string s = ns.NamespaceUri;

                s = Regex.Replace(s, "^(http://)", @"https://");
                s = Regex.Replace(s, "/$", "");

                if (!s.StartsWith("https://"))
                {
                    return("https://" + s);
                }
                return(s);
            }
Beispiel #13
0
        public IEnumerable <string> GetPrefixes(DomNamespace ns, DomScope scope)
        {
            if (ns is null)
            {
                throw new ArgumentNullException(nameof(ns));
            }

            IEnumerable <DomElement> elements;

            if (scope == DomScope.TargetAndAncestors)
            {
                elements = _element.AncestorsAndSelf;
            }
            else
            {
                // We don't do descendant search even if was requested
                elements = new [] { _element };
            }
            return(elements.SelectMany(
                       e => e.Attributes.TrySelect <DomAttribute, string>(TryExtractXmlnsPrefixMapping)
                       ));
        }
Beispiel #14
0
 public string GetPrefix(DomNamespace ns, DomScope scope)
 {
     return(GetPrefixes(ns, scope).FirstOrDefault());
 }
Beispiel #15
0
 internal DefaultImpl(DomNamespace ns, string localName)
 {
     _ns        = ns;
     _localName = localName;
 }
Beispiel #16
0
 public string RegisterPrefix(DomNamespace ns, string preferredPrefix)
 {
     return(Resolver.RegisterPrefix(ns, preferredPrefix));
 }
Beispiel #17
0
 public string GetPrefix(DomNamespace ns, DomScope scope)
 {
     return(Resolver.GetPrefix(ns, scope));
 }
Beispiel #18
0
 public abstract IEnumerable <string> GetPrefixes(DomNamespace ns, DomScope scope);
Beispiel #19
0
 public static DomName Create(DomNamespace namespaceUri, string name)
 {
     return((namespaceUri ?? DomNamespace.Default) + name);
 }
Beispiel #20
0
 public string GetPrefix(DomNamespace ns, DomScope scope)
 {
     return(null);
 }
Beispiel #21
0
 public abstract string RegisterPrefix(DomNamespace ns, string preferredPrefix);
Beispiel #22
0
 public IEnumerable <string> GetPrefixes(DomNamespace ns, DomScope scope)
 {
     return(Enumerable.Empty <string>());
 }
 public override int GetHashCode(DomNamespace obj)
 {
     return(NormalizeUri(obj).GetHashCode());
 }
 public override bool Equals(DomNamespace x, DomNamespace y)
 {
     return(Compare(x, y) == 0);
 }
Beispiel #25
0
 public string RegisterPrefix(DomNamespace ns, string preferredPrefix)
 {
     throw new NotSupportedException();
 }
Beispiel #26
0
 public IEnumerable <string> GetPrefixes(DomNamespace ns, DomScope scope)
 {
     return(Resolver.GetPrefixes(ns, scope));
 }