///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>tries to parse a category collection document</summary> /// <param name="reader"> xmlReader positioned at the start element</param> /// <param name="owner">the base object that the collection belongs to</param> /// <returns></returns> ////////////////////////////////////////////////////////////////////// public AtomCategoryCollection ParseCategories(XmlReader reader, AtomBase owner) { //Tracing.Assert(reader != null, "reader should not be null"); if (reader == null) { throw new ArgumentNullException("reader"); } AtomCategoryCollection ret = new AtomCategoryCollection(); MoveToStartElement(reader); //Tracing.TraceCall("entering Categories Parser"); object localname = reader.LocalName; //Tracing.TraceInfo("localname is: " + reader.LocalName); if (IsCurrentNameSpace(reader, BaseNameTable.AppPublishingNamespace(owner)) && localname.Equals(this.nameTable.Categories)) { //Tracing.TraceInfo("Found categories document"); int depth = -1; while (NextChildElement(reader, ref depth)) { localname = reader.LocalName; if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom)) { if (localname.Equals(this.nameTable.Category)) { AtomCategory category = ParseCategory(reader, owner); ret.Add(category); } } } } else { //Tracing.TraceInfo("ParseCategories called and nothing was parsed" + localname); throw new ClientFeedException("An invalid Atom Document was passed to the parser. This was not an app:categories document: " + localname); } return(ret); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>parses xml to fill a precreated AtomSource object (might be a feed)</summary> /// <param name="reader">correctly positioned reader</param> /// <param name="source">created source object to be filled</param> /// <returns> </returns> ////////////////////////////////////////////////////////////////////// protected void ParseSource(XmlReader reader, AtomSource source) { //Tracing.Assert(reader != null, "reader should not be null"); if (reader == null) { throw new ArgumentNullException("reader"); } //Tracing.Assert(source != null, "source should not be null"); if (source == null) { throw new ArgumentNullException("source"); } //Tracing.TraceCall(); // // atomSource = // element atom:source { // atomCommonAttributes, // (atomAuthor? // & atomCategory* // & atomContributor* // & atomGenerator? // & atomIcon? // & atomId? // & atomLink* // & atomLogo? // & atomRights? // & atomSubtitle? // & atomTitle? // & atomUpdated? // & extensionElement*) // this will also parse the gData extension elements. // } int depth = -1; ParseBasicAttributes(reader, source); while (NextChildElement(reader, ref depth)) { object localname = reader.LocalName; AtomFeed feed = source as AtomFeed; if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom)) { if (localname.Equals(this.nameTable.Title)) { source.Title = ParseTextConstruct(reader, source); } else if (localname.Equals(this.nameTable.Updated)) { source.Updated = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture); } else if (localname.Equals(this.nameTable.Link)) { source.Links.Add(ParseLink(reader, source)); } else if (localname.Equals(this.nameTable.Id)) { source.Id = source.CreateAtomSubElement(reader, this) as AtomId; ParseBaseLink(reader, source.Id); } else if (localname.Equals(this.nameTable.Icon)) { source.Icon = source.CreateAtomSubElement(reader, this) as AtomIcon; ParseBaseLink(reader, source.Icon); } else if (localname.Equals(this.nameTable.Logo)) { source.Logo = source.CreateAtomSubElement(reader, this) as AtomLogo; ParseBaseLink(reader, source.Logo); } else if (localname.Equals(this.nameTable.Author)) { source.Authors.Add(ParsePerson(reader, source)); } else if (localname.Equals(this.nameTable.Contributor)) { source.Contributors.Add(ParsePerson(reader, source)); } else if (localname.Equals(this.nameTable.Subtitle)) { source.Subtitle = ParseTextConstruct(reader, source); } else if (localname.Equals(this.nameTable.Rights)) { source.Rights = ParseTextConstruct(reader, source); } else if (localname.Equals(this.nameTable.Generator)) { source.Generator = ParseGenerator(reader, source); } else if (localname.Equals(this.nameTable.Category)) { // need to make this another colleciton source.Categories.Add(ParseCategory(reader, source)); } else if (feed != null && localname.Equals(this.nameTable.Entry)) { ParseEntry(reader); } // this will either move the reader to the end of an element // if at the end, to the start of a new one. reader.Read(); } else if (feed != null && IsCurrentNameSpace(reader, BaseNameTable.gBatchNamespace)) { // parse the google batch extensions if they are there ParseBatch(reader, feed); } else if (feed != null && IsCurrentNameSpace(reader, BaseNameTable.OpenSearchNamespace(this.versionInfo))) { if (localname.Equals(this.nameTable.TotalResults)) { feed.TotalResults = int.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture); } else if (localname.Equals(this.nameTable.StartIndex)) { feed.StartIndex = int.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture); } else if (localname.Equals(this.nameTable.ItemsPerPage)) { feed.ItemsPerPage = int.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture); } } else { // default extension parsing. ParseExtensionElements(reader, source); } } return; }