Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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# 如何解析xml并读取其值_C#_Xml Parsing_Windows Phone 8 - Fatal编程技术网

C# 如何解析xml并读取其值

C# 如何解析xml并读取其值,c#,xml-parsing,windows-phone-8,C#,Xml Parsing,Windows Phone 8,我使用的是C windows phone 8,我有以下XML <?xml version="1.0" encoding="UTF-8" ?> <login res="SUCCESS" encstatus="DEFAULT" usedquota="0" /> 其中str是xml文件,但所有元素都为空/null。您试图获取属性值,没有元素: XDocument xDoc = XDocument.Parse(str); var pol = (string)xDoc.

我使用的是C windows phone 8,我有以下XML

<?xml version="1.0" encoding="UTF-8" ?> 
 <login res="SUCCESS"  encstatus="DEFAULT" usedquota="0"  />
其中str是xml文件,但所有元素都为空/null。

您试图获取属性值,没有元素:

XDocument xDoc = XDocument.Parse(str);

var pol = (string)xDoc.Root.Attribute("res");
您正在尝试获取属性值,没有元素:

XDocument xDoc = XDocument.Parse(str);

var pol = (string)xDoc.Root.Attribute("res");

这些节点是属性:

 XDocument xDoc = XDocument.Parse(str)
 XElement login = xDoc.Root;
 string res = (string)login.Attribute("res");
 string encstatus = (string)login.Attribute("encstatus");
 int usedquota = (int)login.Attribute("usedquota");

这些节点是属性:

 XDocument xDoc = XDocument.Parse(str)
 XElement login = xDoc.Root;
 string res = (string)login.Attribute("res");
 string encstatus = (string)login.Attribute("encstatus");
 int usedquota = (int)login.Attribute("usedquota");

你想要的是属性,而不是元素。也许通过这种方式我可以得到属性值。实际上,这是服务器的响应。您想要的是属性,而不是元素。通过这种方式,我可以获得属性值。实际上这是服务器的响应。谢谢。。。你帮了我很多。我不知道这这么简单谢谢。。。你帮了我很多。我不知道这这么简单。