简体   繁体   中英

C# XML several occurrences of a same element

I'm currently reading about serialization and C# attributes related to serialization (XmlRoot, XmlElement, XmlArray, ...).

I want to output something like this:

<root>
    <a>...</a>
    <b>...</b>
    <c>...</c>
    <c>...</c>
    <c>...</c>
</root>

(where the c element occurs several times)

But I don't get how to have multiple c without having them inside a specific "array/list node".

Because I really don't want that:

<root>
    <a>...</a>
    <b>...</b>
    <cList>
        <c>...</c>
        <c>...</c>
        <c>...</c>
    </cList>
</root>

How can this be achieved?

Try it like this:

[XmlElement("c")]
public List<c> cList { get; set; }

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