コード例 #1
0
ファイル: source.cs プロジェクト: ruo2012/samples-1
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create and load the XML document.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<!-- sample XML -->" +
                        "<book>" +
                        "<title>Pride And Prejudice</title>" +
                        "<price>19.95</price>" +
                        "</book>");

            //Load the XmlNodeReader
            reader = new XmlNodeReader(doc);

            reader.MoveToContent();                   //Move to the book node.
            reader.Read();                            //Read the book start tag.
            reader.Skip();                            //Skip the title element.

            Console.WriteLine(reader.ReadOuterXml()); //Read the price element.
        }

        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
コード例 #2
0
        private SyndicationFeed MakeSyndicationFeed(Feed feed)
        {
            var xmlSerializer = new XmlSerializer(typeof(List <Item>));
            var xmlns         = new XmlSerializerNamespaces();

            xmlns.Add("g", "http://base.google.com/ns/1.0");

            SyndicationFeed syndicationFeed = new SyndicationFeed();

            using (StringWriter writer = new StringWriter())
            {
                try
                {
                    xmlSerializer.Serialize(writer, feed.Items, xmlns);
                } catch (InvalidOperationException e)
                {
                    Debug.WriteLine(e.ToString());
                }

                XmlDocument xmlDocument = new XmlDocument();

                try
                {
                    xmlDocument.LoadXml(writer.ToString());
                } catch (XmlException e)
                {
                    Debug.WriteLine(e.ToString());
                }

                using (XmlReader xmlReader = new XmlNodeReader(xmlDocument.DocumentElement))
                {
                    bool canRead = xmlReader.Read();
                    while (canRead)
                    {
                        if ((xmlReader.Name == "item") && xmlReader.IsStartElement())
                        {
                            string outerxml = xmlReader.ReadOuterXml();
                            canRead = (outerxml != string.Empty);

                            syndicationFeed.ElementExtensions.Add(xmlReader);
                        }
                        else
                        {
                            canRead = xmlReader.Read();
                        }
                    }
                }
            }

            //Add basic feed information
            syndicationFeed.Title           = new TextSyndicationContent(feed.Title);
            syndicationFeed.Description     = new TextSyndicationContent("Google Merchant Centre Feed, Generated by EasywebshopProductFeedAdapter");
            syndicationFeed.Generator       = "EasywebshopProductFeedAdapter";
            syndicationFeed.LastUpdatedTime = feed.Updated;

            return(syndicationFeed);
        }
コード例 #3
0
        /// <summary>
        /// Parses an IM log file and sends the information to GDS
        /// </summary>
        /// <param name="logFile">The IM conversations log file</param>
        /// <param name="lastIndexed">messages older than this will not be sent to GDS</param>
        private void ParseAndSendMessages(string logFile, DateTime lastIndexed)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(logFile);
            XmlNodeReader reader = new XmlNodeReader(doc);

            // reset user and buddy name
            userName  = null;
            buddyName = null;

            // Moves the reader to the root element.
            reader.MoveToContent();

            // move to the first message
            reader.Read();

            while (reader.LocalName == "Message")
            {
                // check the date of the message - if older skip
                reader.MoveToAttribute("DateTime");
                DateTime messageDateTime = DateTime.Parse(reader.Value);
                reader.MoveToElement();

                // if older than the last indexing time, skip the message
                if (messageDateTime.CompareTo(lastIndexed) <= 0)
                {
                    reader.Skip();
                    continue;
                }

                // get message data
                MSNMessageData messageData = ParseMessageData(reader.ReadOuterXml());

                // send this message to GDS for indexing
                SendMessageData(messageData);
            }
        }