Possible Duplicate:
Deserializing XML, how do I access attributes?
I am deserializing the following XML:
<root>
<foo> some content </foo>
<bar id="someId">someContent</bar>
</root>
Into a Class object below using XMLSerializer.
[XmlRootAttribute("foobar")]
public class foobar
{
[XmlElementAttribute("foo")]
public string foo { get; set; }
[XmlElementAttribute("bar")]
public string bar { get; set; }
}
However, this does not pick up someId within the bar tag. What change do I need to make to pick it up as well?
I tried this:
In the class above, I changed the second property to:
[XmlElementAttribute("bar")]
public Bar bar { get; set; }
And then defined a new class:
[XmlTypeAttribute]
public class Bar
{
[XmlAttribute("id")]
public string id { get; set; }
[XmlText]
public string Value { get; set; }
}
This still picks up the value but not the Id.
try to use XmlAttribute without (“id”) that should fix it.