. Net (C #): differences between xmlarrayitem and xmlelement in serialized Arrays

Source: Internet
Author: User

For example, the xmlarrayitem attribute is used to indicate the element types in the array:

Public Class A

{

[ Xmlarrayitem (Type = Typeof ( Int )), Xmlarrayitem (Type = Typeof ( Guid )), Xmlarrayitem (Type = Typeof ( String )]

Public Object[] Arr= New Object[] {12,"Hehe",Guid.Newguid ()};

}

 

The serialized XML is:

<A Xmlns: xsi="Http://www.w3.org/2001/XMLSchema-instance"

Xmlns: XSD="Http://www.w3.org/2001/XMLSchema">

<Arr>

<Int>12</Int>

<String>Hehe</String>

<Guid>291b7cba-fc32-4019-bb22-d5d61643b6a7</Guid>

</Arr>

</A>

The arr field name is written as an XML element.

 

However, if you change xmlarrayitem to xmlelement:

Public Class A

{

[ Xmlelement (Type = Typeof ( Int )), Xmlelement (Type = Typeof ( Guid )), Xmlelement (Type = Typeof ( String )]

Public Object[] Arr= New Object[] {12,"Hehe",Guid.Newguid ()};

}

 

The serialized XML is as follows:

<A Xmlns: xsi="Http://www.w3.org/2001/XMLSchema-instance"

Xmlns: XSD="Http://www.w3.org/2001/XMLSchema">

<Int>12</Int>

<String>Hehe</String>

<Guid>5e7da5a0-d513-47b7-ae8f-80b404a9b0d4</Guid>

</A>

 

There is no arr field name!

Note that you can use xmlarrayitem or elementname of xmlelement to control the names of XML elements of the corresponding type.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.