Specify parent element name in XMLElementAttribute

  • Thread starter Thread starter Wild.Bill
  • Start date Start date
W

Wild.Bill

Guest
I've created my classes to match a 3rd party schema. This is working, but I had to create dozens of classes to get the hierarchy correct. What I would like to do is simplify my class, but keep the correct serialization from my objects to this schema. Example

I'm trying to get

<foo>
<xyzBar>
<SomethingTooLongButMatchesXSD />
</xyzBar>
</foo>

Currently I set my classes up like this

public class foo
{
[XmlElementAttribute("xyzBar")]
public xyzBar Bar { get; set; }
}
public class xyzBar
{
public string SomethingTooLongButMatchesXSD;
}

But I would like to organize like this

public class foo
{
[XmlElementAttribute(@"xyzBar/SomethingTooLongButMatchesXSD")]
public string Short;
}

Continue reading...
 
Back
Top