Пример #1
0
 public bool AddCategory(SFCategory cat)         //string value, string scheme = null, string term = null)
 {
     if (cat != null && cat.PrepValues())
     {
         Categories.Add(cat);
         return(true);
     }
     return(false);
 }
Пример #2
0
        public void AddCategories(XElement item)
        {
            if (item != null)
            {
                // gets any 'category' elements or any 'atom:category' elements
                foreach (var xcat in item.Elements().Where(e => e.Name == "category" || e.Name == SimpleFeed.xname_Atom_Category))                  // .Elements("category")) {
                {
                    if (xcat != null)
                    {
                        string     val = xcat.ValueN().NullIfEmptyTrimmed();                     // MUST trim this one here for next step
                        SFCategory cat = null;

                        // note that 'term' is a REQUIRED attribute for ATOM
                        if (xcat.HasAttributes)
                        {
                            if (val.IsNulle())
                            {
                                val = xcat.Attributes().FirstOrDefault(a => a.Name == "term").ValueN().TrimIfNeeded();
                            }

                            if (val.IsNulle())
                            {
                                return;
                            }

                            cat = new SFCategory()
                            {
                                Scheme = xcat.Attributes().FirstOrDefault(a => a.Name == "domain" || a.Name == "scheme").ValueN(),
                                Label  = xcat.Attribute("label").ValueN(),
                            };
                        }
                        else
                        {
                            cat = new SFCategory();
                        }

                        if (val.IsNulle())
                        {
                            return;
                        }

                        cat.Value = val;
                        AddCategory(cat);
                    }
                }
            }
        }