0
<query xmlns="urn:xmpp:dialogueHistory">
<dialogueHistory id="4d38f289-9">
<MessageID>26164</MessageID>
<messageText>Fhh</messageText>
<msgDate>11/25/2016 6:30:39 AM</msgDate>
<unReadCount>0</unReadCount>
</dialogueHistory>
</query>

get information of messageid,messagetext

how can I get the information from the above xml using agsxmpp library

namespace is agsXMPP.Xml.Dom

bilal
  • 648
  • 8
  • 26

1 Answers1

0

You need to specify the namespace. Using xml linq

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);

            List<XElement> dialogueHistory = doc.Descendants().Where(x => x.Name.LocalName == "dialogueHistory").ToList();
            XNamespace ns = dialogueHistory.FirstOrDefault().GetDefaultNamespace();

            var results = dialogueHistory.Select(x => new {
                id = (string)x.Attribute("id"),
                messageId = (int)x.Element(ns + "MessageID"),
                messageText = (string)x.Element(ns + "messageText"),
                messageDate = (DateTime)x.Element(ns + "msgDate"),
                unReadCount = (int)x.Element(ns + "unReadCount")
            }).ToList();

        }
    }
}
jdweng
  • 33,250
  • 2
  • 15
  • 20