简体   繁体   中英

Get Value from XML tag

I have the following code:

p.tel.FirstOrDefault(t => t.teltype == "mobile").ToString()

 <person> <name>Donald Duck</name> <tel teltype="voice" /> <tel teltype="mobile">01000000</tel> </person> 

The c# class for the xml look like this:

[System.Xml.Serialization.XmlElementAttribute("tel")]
public enterprisePersonTel[] tel {
    get {
        return this.telField;
    }
    set {
        this.telField = value;
    }
}

My code returns: enterprisePersonTel

This doesn't work

p.tel.FirstOrDefault(t => t.teltype == "mobile").Value

How can I get the actual telephone number?

The class for the attribute was not generated correctly

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;
    }
}**

} The ** part of the text was missing when using paste as class in Visual studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM