Ser*_*pia 1 .net c# xml linq-to-xml
我正在尝试检查XML响应中是否存在用户.
当用户不存在时,响应如下:
<ipb></ipb>
Run Code Online (Sandbox Code Playgroud)
对于我(在代码中)验证用户不存在的最佳方法是什么?我在考虑检查它是否没有任何子元素,但我有点困惑.
谢谢您的帮助!
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;
}
}
Run Code Online (Sandbox Code Playgroud)
if (doc.Root.Elements().Any())
{
// User was found
}
Run Code Online (Sandbox Code Playgroud)
要么
XElement profile = doc.Root.Element("profile");
if (profile != null)
{
// User was found
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5895 次 |
| 最近记录: |