Link to home
Create AccountLog in
Avatar of njgroup
njgroup

asked on

how to get the count of all xml nodes selected using linq?

hi,

how to get the count of all xml nodes selected using linq?

here is my code snippet:

 
XDocument xmlvisitors = XDocument.Load(xml_visitor_path);

            var visitors = from visitor in xmlvisitors.Descendants("Visitor")
                           orderby DateTime.Parse(visitor.Element("date").Value.Split('_')[1].Substring(4, 2) + "/" + visitor.Element("date").Value.Split('_')[1].Substring(6, 2) + "/" + visitor.Element("date").Value.Split('_')[1].Substring(0, 4) + " " + visitor.Element("time").Value.Substring(0, 2) + ":" + visitor.Element("time").Value.Substring(2, 2) + ":00") descending
                           select new
                           {
                               hostIPAddress = visitor.Element("hostIPAddress").Value,
                               hostName = visitor.Element("hostName").Value,
                               hostLocation = visitor.Element("hostLocation").Value,
                               hostBrowserType = visitor.Element("hostBrowserType").Value,
                               hostBrowserVersion = visitor.Element("hostBrowserVersion").Value,
                               serverIPAddress = visitor.Element("serverIPAddress").Value,
                               serverLocation = visitor.Element("serverLocation").Value,
                               date = visitor.Element("date").Value,
                               time = visitor.Element("time").Value,
                           };
            int count = visitors.Count<int>;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary Davis
Gary Davis
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account