示例#1
0
 /// <summary>
 /// Persistence method for the Comment  object
 /// </summary>
 /// <param name="writer">the xmlwriter to write into</param>
 public void Save(XmlWriter writer)
 {
     if (FeedLink != null)
     {
         // only save out if there is something to save
         writer.WriteStartElement(XmlPrefix, XmlName, XmlNameSpace);
         FeedLink.Save(writer);
         writer.WriteEndElement();
     }
 }
示例#2
0
 //////////////////////////////////////////////////////////////////////
 /// <summary>Parses an xml node to create a Where  object.</summary>
 /// <param name="node">the node to parse node</param>
 /// <param name="parser">the xml parser to use if we need to dive deeper</param>
 /// <returns>the created Where  object</returns>
 //////////////////////////////////////////////////////////////////////
 public IExtensionElementFactory CreateInstance(XmlNode node, AtomFeedParser parser)
 {
     return(FeedLink.ParseFeedLink(node));
 }
示例#3
0
        /////////////////////////////////////////////////////////////////////////////


        #region FeedLink Parser
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create an FeedLink object.</summary>
        /// <param name="node">feedLink node</param>
        /// <returns> the created FeedLink object</returns>
        //////////////////////////////////////////////////////////////////////
        public static FeedLink ParseFeedLink(XmlNode node)
        {
            //Tracing.TraceCall();
            FeedLink link = null;

            //Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            object localname = node.LocalName;

            if (localname.Equals(GDataParserNameTable.XmlFeedLinkElement))
            {
                link = new FeedLink();
                if (node.Attributes != null)
                {
                    if (node.Attributes[GDataParserNameTable.XmlAttributeHref] != null)
                    {
                        link.Href = node.Attributes[GDataParserNameTable.XmlAttributeHref].Value;
                    }

                    if (node.Attributes[GDataParserNameTable.XmlAttributeReadOnly] != null)
                    {
                        link.ReadOnly = node.Attributes[GDataParserNameTable.XmlAttributeReadOnly].Value.Equals(Utilities.XSDTrue);
                    }
                    if (node.Attributes[GDataParserNameTable.XmlAttributeRel] != null)
                    {
                        link.Rel = node.Attributes[GDataParserNameTable.XmlAttributeRel].Value;
                    }
                    if (node.Attributes[GDataParserNameTable.XmlAttributeCountHint] != null)
                    {
                        try
                        {
                            link.CountHint = Int32.Parse(node.Attributes[GDataParserNameTable.XmlAttributeCountHint].Value);
                        }
                        catch (FormatException fe)
                        {
                            throw new ArgumentException("Invalid g:feedLink/@countHint.", fe);
                        }
                    }
                }

                if (node.HasChildNodes)
                {
                    XmlNode feedChild = node.FirstChild;
                    while (feedChild != null && feedChild is XmlElement)
                    {
                        if (feedChild.LocalName == AtomParserNameTable.XmlFeedElement &&
                            feedChild.NamespaceURI == BaseNameTable.NSAtom)
                        {
                            if (link.Feed == null)
                            {
                                link.Feed = new AtomFeed(null, new Service());
                                Stream feedStream =
                                    new MemoryStream(ASCIIEncoding.Default.GetBytes(feedChild.OuterXml));

                                link.Feed.Parse(feedStream, AlternativeFormat.Atom);
                            }
                            else
                            {
                                throw new ArgumentException("Only one feed is allowed inside the g:feedLink");
                            }
                        }
                        feedChild = feedChild.NextSibling;
                    }
                }
            }

            return(link);
        }