Exemple #1
0
        public static T GetAttribute <T>(this HtmlNode node, string attributeName, T def = default)
        {
            var r = node.GetAttribute(attributeName, default(string));

            if (r == null)
            {
                return(def);
            }
            return((T)Convert.ChangeType(r, typeof(T)));
        }
Exemple #2
0
        public static bool GetAttribute(this HtmlNode node, string attributeName, bool def = default)
        {
            var r = node.GetAttribute(attributeName, default(string));

            if (r == null)
            {
                return(def);
            }
            return(true);
        }
Exemple #3
0
        public static Uri GetAttribute(this HtmlNode node, string attributeName, Uri baseUri, Uri def = default)
        {
            var r = node.GetAttribute(attributeName, default(string));

            if (r == null)
            {
                return(def);
            }
            return(new Uri(baseUri, r));
        }
Exemple #4
0
        public static int GetAttribute(this HtmlNode node, string attributeName, int def = default)
        {
            var r = node.GetAttribute(attributeName, default(string));

            if (r == null)
            {
                return(def);
            }
            if (int.TryParse(r, out var intP))
            {
                return(intP);
            }
            return(def);
        }
Exemple #5
0
        public IDictionary<string, string> UpdatePrefixMappings(ParserContext context, HtmlNode elementNode)
        {
            if (elementNode.HasAttribute(Constants.Prefix_RDFaAttribute))
            {
                var mappings = new Dictionary<string, string>(context.PrefixMappings);

                string[] splits = Regex.Split(elementNode.GetAttribute(Constants.Prefix_RDFaAttribute).Value, "\\s+");
                int i = 0;
                while (i < splits.Length)
                {
                    var prefix = splits[i].Split(':')[0];
                    var url = splits[i + 1];

                    if (prefix == "_")
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(prefix) && !mappings.ContainsKey(prefix))
                    {
                        mappings.Add(prefix, url);
                    }

                    i += 2;
                }

                if (mappings.Count > context.PrefixMappings.Count)
                    context.PrefixMappings = mappings;

            }
            return context.PrefixMappings;
        }