private Feed(System.Xml.XmlDocument i_FeedSyncXmlDocument) { m_XmlDocument = i_FeedSyncXmlDocument; m_XmlNamespaceManager = new System.Xml.XmlNamespaceManager(m_XmlDocument.NameTable); if (m_XmlDocument.DocumentElement.LocalName == Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_CONTAINER_ELEMENT_NAME) m_FeedType = Microsoft.Samples.FeedSync.Feed.FeedTypes.Atom; else m_FeedType = Microsoft.Samples.FeedSync.Feed.FeedTypes.RSS; this.InitializeXmlNamespaceManager(false); if (m_FeedType == Microsoft.Samples.FeedSync.Feed.FeedTypes.Atom) { m_FeedItemXPathQuery = System.String.Format ( "{0}:{1}", m_AtomNamespacePrefix, Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_ELEMENT_NAME ); if (m_XmlNamespaceManager.DefaultNamespace == Microsoft.Samples.FeedSync.Constants.ATOM_XML_NAMESPACE_URI) m_FeedItemElementName = Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_ELEMENT_NAME; else m_FeedItemElementName = m_FeedItemXPathQuery; } else { m_FeedItemXPathQuery = Microsoft.Samples.FeedSync.Constants.RSS_FEED_ITEM_ELEMENT_NAME; m_FeedItemElementName = m_FeedItemXPathQuery; } // Get reference to 'sx:sharing' element string XPathQuery = System.String.Format ( "{0}:{1}", m_FeedSyncNamespacePrefix, Microsoft.Samples.FeedSync.Constants.SHARING_ELEMENT_NAME ); System.Xml.XmlElement SharingXmlElement = (System.Xml.XmlElement)this.ItemContainerXmlElement.SelectSingleNode ( XPathQuery, m_XmlNamespaceManager ); if (SharingXmlElement != null) m_SharingNode = new Microsoft.Samples.FeedSync.SharingNode(this, SharingXmlElement); // Iterate items System.Xml.XmlNodeList FeedItemXmlNodeList = this.ItemContainerXmlElement.SelectNodes ( m_FeedItemXPathQuery, m_XmlNamespaceManager ); foreach (System.Xml.XmlElement FeedItemXmlElement in FeedItemXmlNodeList) { Microsoft.Samples.FeedSync.FeedItemNode FeedItemNode = Microsoft.Samples.FeedSync.FeedItemNode.CreateFromXmlElement ( this, FeedItemXmlElement ); m_FeedItemNodeSortedList[FeedItemNode.SyncNode.ID] = FeedItemNode; } this.Initialize(); }
private Feed(System.Xml.XmlDocument i_FeedXmlDocument, int? i_SequenceIDBase, string i_Since, string i_Until) { m_XmlDocument = i_FeedXmlDocument; m_XmlNamespaceManager = new System.Xml.XmlNamespaceManager(m_XmlDocument.NameTable); if (m_XmlDocument.DocumentElement.LocalName == Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_CONTAINER_ELEMENT_NAME) m_FeedType = Microsoft.Samples.FeedSync.Feed.FeedTypes.Atom; else m_FeedType = Microsoft.Samples.FeedSync.Feed.FeedTypes.RSS; this.InitializeXmlNamespaceManager(true); if (m_FeedType == Microsoft.Samples.FeedSync.Feed.FeedTypes.Atom) { m_FeedItemXPathQuery = System.String.Format ( "{0}:{1}", m_AtomNamespacePrefix, Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_ELEMENT_NAME ); if (m_XmlNamespaceManager.DefaultNamespace == Microsoft.Samples.FeedSync.Constants.ATOM_XML_NAMESPACE_URI) m_FeedItemElementName = Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_ELEMENT_NAME; else m_FeedItemElementName = m_FeedItemXPathQuery; } else { m_FeedItemXPathQuery = Microsoft.Samples.FeedSync.Constants.RSS_FEED_ITEM_ELEMENT_NAME; m_FeedItemElementName = m_FeedItemXPathQuery; } // Get reference to 'sx:sharing' element string XPathQuery = System.String.Format ( "{0}:{1}", m_FeedSyncNamespacePrefix, Microsoft.Samples.FeedSync.Constants.SHARING_ELEMENT_NAME ); System.Xml.XmlElement SharingXmlElement = (System.Xml.XmlElement)this.ItemContainerXmlElement.SelectSingleNode ( XPathQuery, m_XmlNamespaceManager ); XPathQuery = System.String.Format ( "descendant::*[{0}:{1}]", m_FeedSyncNamespacePrefix, Microsoft.Samples.FeedSync.Constants.SYNC_ELEMENT_NAME ); System.Xml.XmlNodeList SyncXmlNodeList = this.ItemContainerXmlElement.SelectNodes ( XPathQuery, m_XmlNamespaceManager ); if ((SharingXmlElement != null) || (SyncXmlNodeList.Count > 0)) throw new System.Exception("Document is already a valid FeedSync document!"); System.Xml.XmlNodeList FeedItemXmlNodeList = this.ItemContainerXmlElement.SelectNodes ( m_FeedItemXPathQuery, m_XmlNamespaceManager ); // BIG HONKING NOTE: Iterate nodes using index instead of enumerator for (int Index = 0; Index < FeedItemXmlNodeList.Count; ++Index) { System.Xml.XmlElement FeedItemXmlElement = (System.Xml.XmlElement)FeedItemXmlNodeList[Index]; // Remove item from document FeedItemXmlElement.ParentNode.RemoveChild(FeedItemXmlElement); string SyncNodeID = null; if (i_SequenceIDBase != null) { ++i_SequenceIDBase; SyncNodeID = i_SequenceIDBase.ToString(); } // Create new FeedItemNode and add it to feed Microsoft.Samples.FeedSync.FeedItemNode FeedItemNode = Microsoft.Samples.FeedSync.FeedItemNode.CreateNewFromXmlElement ( this, FeedItemXmlElement, SyncNodeID ); this.AddFeedItem(FeedItemNode); } this.Initialize(); }
private Feed(string i_Title, string i_Description, string i_Link, Microsoft.Samples.FeedSync.Feed.FeedTypes i_FeedType) { string XmlDocumentContents; if (i_FeedType == Microsoft.Samples.FeedSync.Feed.FeedTypes.Atom) { XmlDocumentContents = System.String.Format ( Microsoft.Samples.FeedSync.Constants.ATOM_FEED_TEMPLATE, Microsoft.Samples.FeedSync.MiscHelpers.XMLEncode(i_Title), Microsoft.Samples.FeedSync.MiscHelpers.XMLEncode(i_Description), Microsoft.Samples.FeedSync.MiscHelpers.XMLEncode(i_Link), System.DateTime.Now.ToUniversalTime().ToString(Microsoft.Samples.FeedSync.Constants.DATE_STRING_FORMAT), System.Reflection.Assembly.GetExecutingAssembly().Location, System.Guid.NewGuid().ToString() ); } else { XmlDocumentContents = System.String.Format ( Microsoft.Samples.FeedSync.Constants.RSS_FEED_TEMPLATE, Microsoft.Samples.FeedSync.MiscHelpers.XMLEncode(i_Title), Microsoft.Samples.FeedSync.MiscHelpers.XMLEncode(i_Description), Microsoft.Samples.FeedSync.MiscHelpers.XMLEncode(i_Link) ); } m_XmlDocument = new System.Xml.XmlDocument(); m_XmlDocument.LoadXml(XmlDocumentContents); m_XmlNamespaceManager = new System.Xml.XmlNamespaceManager(m_XmlDocument.NameTable); this.InitializeXmlNamespaceManager(false); m_FeedType = i_FeedType; if (m_FeedType == Microsoft.Samples.FeedSync.Feed.FeedTypes.Atom) { m_FeedItemXPathQuery = System.String.Format ( "{0}:{1}", m_AtomNamespacePrefix, Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_ELEMENT_NAME ); if (m_XmlNamespaceManager.DefaultNamespace == Microsoft.Samples.FeedSync.Constants.ATOM_XML_NAMESPACE_URI) m_FeedItemElementName = Microsoft.Samples.FeedSync.Constants.ATOM_FEED_ITEM_ELEMENT_NAME; else m_FeedItemElementName = m_FeedItemXPathQuery; } else { m_FeedItemXPathQuery = Microsoft.Samples.FeedSync.Constants.RSS_FEED_ITEM_ELEMENT_NAME; m_FeedItemElementName = m_FeedItemXPathQuery; } this.Initialize(); }