views:

19

answers:

1

I'm trying to check if a user exists from an XML response.

When a user doesn't exist the response is like this:

<ipb></ipb>

What would be the best way for me to (in code) verify that a user doesn't exist? I was thinking of checking if it didn't have any child elements but I'm somewhat confused.

Thanks for the help!

        public void LoadUserById(string userID)
    {
        doc = XDocument.Load(String.Format("http://www.dreamincode.net/forums/xml.php?showuser={0}", userID));

        if (doc.DescendantNodes().ToList().Count < 1)
        {
            userExists = false;
        }
        else 
        {
            userExists = true;
        }
    }
+2  A: 
if (doc.Root.Elements().Any())
{
    // User was found
}

or

XElement profile = doc.Root.Element("profile");
if (profile != null)
{
    // User was found
}
dtb
It's that simple huh? Thanks! :D
Sergio Tapia