Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查XDocument是否至少有一个子文档?_C#_.net_Xml_Linq To Xml - Fatal编程技术网

C# 如何检查XDocument是否至少有一个子文档?

C# 如何检查XDocument是否至少有一个子文档?,c#,.net,xml,linq-to-xml,C#,.net,Xml,Linq To Xml,我试图检查XML响应中是否存在用户 当用户不存在时,响应如下: <ipb></ipb> 我(在代码中)验证用户不存在的最佳方法是什么?我想检查它是否没有任何子元素,但我有点困惑 谢谢你的帮助 public void LoadUserById(string userID) { doc = XDocument.Load(String.Format("http://www.dreamincode.net/forums/xml.php

我试图检查XML响应中是否存在用户

当用户不存在时,响应如下:

<ipb></ipb>

我(在代码中)验证用户不存在的最佳方法是什么?我想检查它是否没有任何子元素,但我有点困惑

谢谢你的帮助

        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;
        }
    }
public void LoadUserById(字符串userID)
{
doc=XDocument.Load(String.Format(“http://www.dreamincode.net/forums/xml.php?showuser={0}(userID));
if(doc.degenantnodes().ToList().Count<1)
{
userExists=false;
}
其他的
{
userExists=true;
}
}


就这么简单吧?谢谢就这么简单吧?谢谢D
if (doc.Root.Elements().Any())
{
    // User was found
}
XElement profile = doc.Root.Element("profile");
if (profile != null)
{
    // User was found
}