c# - 从 XML 标记中获取值
问题描述
我有以下代码:
p.tel.FirstOrDefault(t => t.teltype == "mobile").ToString()
<person>
<name>Donald Duck</name>
<tel teltype="voice" />
<tel teltype="mobile">01000000</tel>
</person>
xml 的 c# 类如下所示:
[System.Xml.Serialization.XmlElementAttribute("tel")]
public enterprisePersonTel[] tel {
get {
return this.telField;
}
set {
this.telField = value;
}
}
我的代码返回:enterprisePersonTel
这不起作用
p.tel.FirstOrDefault(t => t.teltype == "mobile").Value
我怎样才能得到实际的电话号码?
解决方案
未正确生成属性的类
public partial class enterprisePersonTel
{
private string teltypeField;
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string teltype
{
get
{
return this.teltypeField;
}
set
{
this.teltypeField = value;
}
}
/// <remarks/>
**[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}**
在 Visual Studio 中使用粘贴作为类时缺少文本的 ** 部分。
推荐阅读
- jenkins-pipeline - 如何从 Jenkins 共享库运行 vars/script.groovy
- wordpress - Dokan 插件定制
- python - 根据部分匹配组合两个 pandas df
- database - wpdb->get row Select (相当复杂) 查询不起作用
- css - Bootstrap 4表中的自定义边框
- python-3.x - 在gramlin中找到两个节点类型之间的最小长度
- java - 在 Alm 中删除 Run 实例的 java 代码
- docker - 无法在超级账本结构中创建通道
- ruby - 'case' 语句如何在函数中工作?
- android - 设计android应用时如何在我的应用中获取谷歌广告ID?