Realize the sequence of sequence in .NET

xiaoxiao2021-03-05  34

Since I have XML, cross-system data exchange becomes more and more simple. .NET makes XML as the foundation of the underlying data exchange and provides a powerful class library in the .NET framework to enhance XML programming capabilities. These classes are included in the System.xml namespace. In a cross-system data exchange, the sequence of objects and the reverse selecente are heavy. .NET provides this specifically provided a system.xml.Serialization namespace for the sequence of objects.

To understand the serialization of XML, first refer to Microsoft's introduction:

Introducing XML Serialization

XML and SOAP Serialization

Roadmap for XML Serialization in the .NET Framework

.NET is serialized by using the characteristic Attribute control object. E.g:

<

XMLTYPE

"

ORDER

"

)

>

_

Public

Class ORDER

Class Order _ public id as string _ public orderitems () as OrderedItem END CLASS

Public

Class ORDERITEM

Class ORDERITEM _ public itemname as string End Class

The XML after the .NET sequence is:

<

ORDER

>

<

id

>

20050405

id

>

<

Items

>

<

Item

>

<

Name

>

Object sequence

Name

>

Item

>

Items

>

ORDER

>

XMLTYPE: Can be applied to classes, structures, enumerations, and interfaces that are public as public. It defines the names and namespaces of XML types. XMLELEMENT: It defines a field or property to serialize the XML element. Fields or properties must be declared as public. Xmlarray: It defines a field or attribute to serialize the XML collection. Fields or properties must be declared as public. XmlarrayItem: Defines the derived type that can be added to the collection. .NET also provides some other Attribute. All attribute features can be viewed by the following address: ● Attributes That Control XML Serialization How to use these Attribute, please see: ● Controlling XML Serialization Using Attributes With these Attribute, we can easily serialize objects, but who is completed ? Then I need to understand XMLSerializer. ASP.NET is to encode XML Web Services messages using the XMLSerializer class. For information on the XMLSerializer class: ● XMLSerializer class ● XMLSerializer.Serialize method XMLSerializer is also very simple:

DIM

Serializer

AS

New

XMLSERIALIZER (

Gettype

(ORDER))

DIM

Writer

AS

New

Streamwriter (filename)

DIM

o

AS

New

ORDER O.ID

=

"

20050405

"

DIM

Item

AS

ORDERITEM ITEM.ItemName

=

"Object Series"

DIM

Items

0

)

AS

ORDERITEM ITEMS

0

)

=

Item O.OrDerItems

=

Items Serializer.Serialize (Writer, Po) Writer.close ()

转载请注明原文地址:https://www.9cbs.com/read-33852.html

New Post(0)