如何从XML中的属性名称获取属性值 [英] How to get property value from property name in XML

查看:549
本文介绍了如何从XML中的属性名称获取属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的xml



hi this is my xml

<pre lang="text">

<request action="registration">
<element id="id001">
<properties name="username">DV_sonic78
<properties name="password">prabu78







我想用这个XML取用户名值DV_sonic78和密码prabu78



我试过的:






I want to take username value as DV_sonic78 and password as prabu78 from this XML

What I have tried:

<pre lang="c#"> XmlDocument doc = new XmlDocument();
                     doc.LoadXml(StrRequest);
                     XmlElement root = doc.DocumentElement;
                     string s = root.Attributes["username"].InnerText;

推荐答案

应该是 root.Attributes [username]。值 ...并且您的XML看起来有点格式不正确:)
Should be root.Attributes["username"].Value... and your XML look a little bit not well-formed :)


将内部文本更改为Value you将得到该属性的值

string s = root.Attributes [username]。Value;
Change inner text to Value you will get the value of that attribute
string s = root.Attributes["username"].Value;


这篇关于如何从XML中的属性名称获取属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆