Home > Net >  C # a List <string> XML serialization
C # a List <string> XML serialization

Time:10-21

Define the following class
[XmlRoot (" funderService ")]
Public class Request_gl
{
Public Request_gl ()
{
ParamList=new List (a);
}
[XmlAttribute]
Public string functionName {get; The set; }

[XmlArrayItem (" vaule ")]
Public List ParamList {get; The set; }

Public string beanToXml ()
{
//ready for ordering column object
Var format=new XmlSerializer (typeof (Request_gl));
Var stringBuilder=new stringBuilder ();

//set the order ordering XML format
XmlWriterSettings XWS=new XmlWriterSettings ();
XWS. Indent=true;
XWS. OmitXmlDeclaration=true;
XWS. Encoding=Encoding. UTF8;

XmlWriter XmlWriter=XmlTextWriter. Create (stringBuilder, XWS);

//remove to node XMLNS: xsi="http://www.w3.org/2001/XMLSchema-instance" XMLNS: XSD="http://www.w3.org/2001/XMLSchema" attribute
XmlSerializerNamespaces _namespaces=new XmlSerializerNamespaces (
New XmlQualifiedName [] {
New XmlQualifiedName (string. The Empty string. Empty)
});
XmlWriter. WriteStartDocument (true);
Format. Serialize (xmlWriter, this _namespaces);

Return the stringBuilder. ToString ();
}

}

need to serialize into XML format below
1 & lt;/value>
2 & lt;/value>
3 & lt;/value>


But actually serialized from is it


1 & lt;/vaule>
2 & lt;/vaule>
3 & lt;/vaule>
4 & lt;/vaule>


Much & lt; ParamList> Node
Please type how to define to serialize ChengXiang want

CodePudding user response:

 [XmlArrayItem (" vaule ")] 
//replace for
[XmlElement (" vaule ")]
  •  Tags:  
  • C #
  • Related