Reputation: 95
I have a lapsus in my mind and I dont know how I can define a XML attribute in my class... which can appear zero, one or more times in my XML-Element...
this is how my XML-Element look like:
*One SubElement
<MainElement Phase="" Stage="" Element-Name="" Element-Version=""
SubElement-Name="" />
*Two SubElements
<MainElement Phase="" Stage="" Element-Name="" Element-Version=""
SubElement-Name="subElement.1"
SubElement-Name="subElement.2"/>
And this is my class:
public class MainElement
{
[XmlAttribute(AttributeName = "Phase")]
public string ElementPhase {get; set; }
[XmlAttribute(AttributeName = "Stage")]
public string ELementStage {get; set; }
etc...
// my SubElement structure...
}
How you can see, the Attribute "SubElement-Name" can appear cero, one or "x" times, but there is no another XML-Element inside my ..
THanks you in advance!
Upvotes: 0
Views: 976
Reputation: 5781
XML does not allow this and thus, also the XmlReader class would not allow it (and all other Xml technologies are built on XmlReader class). Thus, if you really want to do this, you will have to support it entirely on your own.
XML does support lists, i.e.
<MainElement Phase="" Stage="" Element-Name="" Element-Version="" SubElement-Name="subElement.1 subElement.2"/>
However, I don't know how you have to set the attributes for the XmlSerializer for this.
EDIT: If the XmlSerializer supports it, xsd.exe probably knows how. So the best option is probably to create a Xml Schema (this is a good idea anyway) and create the classes for it through xsd.exe
Upvotes: 3