C# 获取xml里面的信息

低调的感觉 2010-05-24 11:00:19
<soapenv:Body>
<LoginResponse xmlns="http://mediax.huawei.com/webservice/types">
<code xsi:type="xsd:int" xmlns="">200</code>
<description xmlns="">Success</description>
<profile xmlns="">
<userID>1</userID>
<account>
<name>admin</name>
<type>WEB</type>
<password>system</password>
</account>
<purviewIDs>USER_DELETE</purviewIDs>
<purviewIDs>CONFERENCE_DEAF_SELF</purviewIDs>
<purviewIDs>CONFERENCE_MODIFY_ONCE_ORG</purviewIDs>
<session>6545101274068923401846000-1270015060</session>
</profile>
</LoginResponse>
</soapenv:Body>


怎么分别获取里面的值:
string code = "200"
string description = "Success"
string userID = "1"
string name = "admin"
string type = "WEB"
string password = "system"
string[] purviewIDs = new string[3] { "USER_DELETE", "CONFERENCE_DEAF_SELF", "CONFERENCE_MODIFY_ONCE_ORG" }
注:purviewIDs 的个数不定,有可能有5个或者10个
string session = "6545101274068923401846000-1270015060"

哪位知道的
帮我解决下
谢谢
...全文
194 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
RedFish2010 2010-05-26
  • 打赏
  • 举报
回复
这个读xml数据的资料网上一大堆吧
whowhen21 2010-05-26
  • 打赏
  • 举报
回复
gsq_0912 2010-05-26
  • 打赏
  • 举报
回复
加入命名空间:using System.Xml;

XmlDocument doc = new XmlDocument();
doc.Load("c:\\xml\\a.xml");
XmlElement root = doc.DocumentElement;
// 获得1的值与属性
root.SelectNodes("user")[0].InnerText; // 值
root.SelectNodes("user")[0].Attributes[0].InnerText; // 属性

// 获得2的值与属性
root.SelectNodes("user")[1].InnerText;
root.SelectNodes("user")[1].Attributes[0].InnerText;

// 获得3的属性与old节
root.SelectNodes("user")[2].Attributes[0].InnerText; // 属性
root.SelectNodes("user")[2]["old"].InnerText; // OLD节
njw1028 2010-05-26
  • 打赏
  • 举报
回复
1、2楼正解。
hangang7403 2010-05-26
  • 打赏
  • 举报
回复
帮忙顶起
请叫我卷福 2010-05-26
  • 打赏
  • 举报
回复
jianuMan 2010-05-26
  • 打赏
  • 举报
回复
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(file);
XmlNode xnRoot = xmldoc.SelectSingelNode();

多个节点就用遍历的方式
xnRoot.ChildNodes

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧