使用属性的 LINQ to XML 解析
我有一个像这样的 xml 文件:
<users>
<user name="user" password="123" email="[email protected]"/>
</users>
我需要编写代码将属性值复制到对象类型变量,但找不到任何适合我需要的内容。我成功编写的代码的某些部分是:
public static UserInfo GetUser()
{
XDocument users = XDocument.Load(FilePath.UserConfigurationPath);
UserInfo usersvar = new UserInfo();
}
这里我必须返回对象并将其与文本框值进行比较。
谁能告诉我如何将值复制到对象中?
I have an xml file like this:
<users>
<user name="user" password="123" email="[email protected]"/>
</users>
I need to write a code to copy the attribute values to a object type variable and I can't find anything which suits my needs. some part of the code which I have successfully written is:
public static UserInfo GetUser()
{
XDocument users = XDocument.Load(FilePath.UserConfigurationPath);
UserInfo usersvar = new UserInfo();
}
Here I have to return the object and compare it with a textbox value.
Can anybody please tell me how I can copy the values to the object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解析所有用户:
如果文档仅包含一个用户或者您想解析第一个用户:
To parse all the users:
If the document contains exactly one user or you want to parse exactly the first: