I need the following output from Pojo classes to Xml.
It's .net 4.6.1, C#.
Problem is in the namespaces and the produced prefixes.
How can I get the node:
<blablubb:Message SOAP-ENV:mustUnderstand="1" xmlns:blablubb="urn:blablubb-com:schemas:blablubb">
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<blablubb:Message SOAP-ENV:mustUnderstand="1" xmlns:blablubb="urn:blablubb-com:schemas:blablubb">
<blablubb:Type>INET_TRANS</blablubb:Type>
<blablubb:Function>RECEIVE_CUSTOMER_ORDER</blablubb:Function>
<blablubb:Sender>CONNECT</blablubb:Sender>
<blablubb:Receiver>CONNECT</blablubb:Receiver>
<blablubb:SentAt>2018-08-30T10:43:37+02:00</blablubb:SentAt>
<blablubb:ExpiresAt>2018-09-30T10:43:37+02:00</blablubb:ExpiresAt>
</blablubb:Message>
</SOAP-ENV:Header>
<SOAP-ENV:Body><ORDERS xmlns="urn:blablubb-com:schemas:inbound_distribution_transactions_create_customer_order_request" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BUYER></BUYER>
<CONTACT_REFERENCE>OAK</CONTACT_REFERENCE>
<EAN_LOCATION_DELIVERY_ADDRESS>10901000</EAN_LOCATION_DELIVERY_ADDRESS>
<CURRENCY_CODE>EUR</CURRENCY_CODE>
<ORDER_DATE>2018-08-27T09:01:01</ORDER_DATE>
<OUR_CUSTOMER_NO>2</OUR_CUSTOMER_NO>
<SUPPLIER_ADDRESS_NO></SUPPLIER_ADDRESS_NO>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Pojos that get serialized:
SoapDocument:
[Serializable]
[XmlRoot("Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
[XmlInclude(typeof(SoapHeader))]
public class SoapDocument {
[XmlElement("Header")]
public SoapHeader soapHeader { get; set; }
[XmlElement("Body",typeof(IfsOrdersXmlDocument))]
public object soapBody { get; set; }
}
SoapHeader :
[Serializable]
[XmlRoot("Header")]
[XmlInclude(typeof(SoapMessage))] // include type class IfsOrderLineXmlDocument
public class SoapHeader {
[XmlElement("Message", Namespace = "urn:blablubb-com:schemas:blablubb")]
public SoapMessage soapMessage { get; set; }
}
SoapBody :
[Serializable]
[XmlInclude(typeof(IfsXmlDocument)), XmlInclude(typeof(IfsOrdersXmlDocument))]
[SoapInclude(typeof(IfsXmlDocument)), SoapInclude(typeof(IfsOrdersXmlDocument))]
public class SoapBody {
[XmlElement("Body")]
public IfsXmlDocument soapBody { get; set; }
}
SoapMessage:
[Serializable]
//[XmlType("blablubb")]
[XmlRoot("Message", Namespace = "urn:blablubb-com:schemas:blablubb")]
public class SoapMessage {
[XmlElement("Type")]
public string Type { get; set; }
[XmlElement("Function")]
public string Function { get; set; }
[XmlElement("Sender")]
public string Sender { get; set; }
[XmlElement("Receiver")]
public string Receiver { get; set; }
[XmlElement("SentAt")]
public string SentAt { get; set; }
[XmlElement("ExpiresAt")]
public string ExpiresAt { get; set; }
}
Code that produces the Xml,
So the problem is in the namespaces and prefixes ......
XmlSerializerNamespaces ns = createSoapDocument();
XmlSerializer serializer = new XmlSerializer(typeof(HeinzApi.Soap.SoapDocument), new Type[] { typeof(IfsXmlDocument), typeof(IfsOrdersXmlDocument) });
FileStream fs = new FileStream(xmlTargetPath, FileMode.Create);
serializer.Serialize(fs, soapDocument, ns);
fs.Close();`
And this is what I get:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<Message xmlns="urn:blablubb-com:schemas:blablubb">
<Type>INET_TRANS</Type>
<Function>RECEIVE_CUSTOMER_ORDER</Function>
<Sender>CONNECT</Sender>
<Receiver>CONNECT</Receiver>
<SentAt>2018-01-03T10:43:37+02:00</SentAt>
<ExpiresAt>2018-08-02T10:43:37+02:00</ExpiresAt>
</Message>
</SOAP-ENV:Header>
</SOAP-ENV:Envelope>
This is the createSoapDocument method that adds namespaces to the XmlSerializer Namespaces object:
private XmlSerializerNamespaces createSoapDocument() {
soapMessage.Type = "INET_TRANS";
soapMessage.Function = "RECEIVE_CUSTOMER_ORDER";
soapMessage.Sender = "CONNECT";
soapMessage.Receiver = "CONNECT";
soapMessage.SentAt = "2018-01-03T10:43:37+02:00";
soapMessage.ExpiresAt = "2018-08-02T10:43:37+02:00";
soapHeader.soapMessage = soapMessage;
soapDocument.soapHeader = soapHeader;
//soapDocument.soapBody = (IfsXmlDocument)targetXmlBaseDocument; ;
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
ns.Add("blablubb", "urn:blablubb-com:schemas:blablubb");
return ns;
}
Edit: This is the result after adding the namespaces to XmlSerializerNamespaces:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:blablubb="urn:blablubb-com:schemas:blablubb" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<blablubb:Message>
<blablubb:Type>INET_TRANS</blablubb:Type>
<blablubb:Function>RECEIVE_CUSTOMER_ORDER</blablubb:Function>
<blablubb:Sender>CONNECT</blablubb:Sender>
<blablubb:Receiver>CONNECT</blablubb:Receiver>
<blablubb:SentAt>2018-01-03T10:43:37+02:00</blablubb:SentAt>
<blablubb:ExpiresAt>2018-08-02T10:43:37+02:00</blablubb:ExpiresAt>
</blablubb:Message>
</SOAP-ENV:Header>
</SOAP-ENV:Envelope>
You need to tell the serializer about your blahblubb namespace by adding it to your XmlSerializerNamespaces object.
ns.Add("blablubb", "urn:bla-com:schemas:blablubb");
Don't forget to change
[XmlElement("Body")]
to
[XmlElement("Body", Namespace="urn:bla-com:schemas:blablubb")]
Related
There is a WSDL scheme for SOAP in OTRS, unfortunately with an automaton (connecting links), it does not work, because Sharp considers the file to be incorrect. for normal operation, you must obtain the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="http://www.otrs.org/TicketConnector/">
<soapenv:Header/>
<soapenv:Body>
<SessionCreate>
<tic:UserLogin>ULogin</tic:UserLogin>
<tic:CustomerUserLogin>CustUser</tic:CustomerUserLogin>
<tic:Password>ULPassword</tic:Password>
</SessionCreate>
</soapenv:Body>
</soapenv:Envelope>
I tried through System.Runtime.Serialization.Formatters.Soap as follows:
[Serializable]
public partial class Envelope
{
/// <remarks/>
public object Header { get; set; }
/// <remarks/>
public EnvelopeBody Body { get; set; }
}
[Serializable]
public partial class EnvelopeBody
{
public SessionCreate SessionCreate { get; set; }
}
[Serializable]
[System.Xml.Serialization.SoapType(IncludeInSchema =true, Namespace = "")]
public partial class SessionCreate
{
/// <remarks/>
[System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
public string UserLogin { get; set; }
/// <remarks/>
[System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
public string CustomerUserLogin { get; set; }
/// <remarks/>
[System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
public string Password { get; set; }
}
class TEST
{
void GetSoap()
{
var model = new SessionCreate
{
UserLogin ="ULogin",
CustomerUserLogin="CustUser",
Password="ULPassword"
};
var en = new Envelope
{
Body = new EnvelopeBody
{
SessionCreate = model
}
};
SoapFormatter formatter = new SoapFormatter();
var ms = new MemoryStream();
formatter.Serialize(ms, en);
Console.WriteLine(StreamToString(ms));
}
string StreamToString(Stream stream)
{
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
}
As a result, it displays the following:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:Envelope id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_Header_x003E_k__BackingField xsi:type="xsd:anyType" xsi:null="1"/>
<_x003C_Body_x003E_k__BackingField href="#ref-3"/>
</a1:Envelope>
<a1:EnvelopeBody id="ref-3" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_SessionCreate_x003E_k__BackingField href="#ref-4"/>
</a1:EnvelopeBody>
<a1:SessionCreate id="ref-4" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_UserLogin_x003E_k__BackingField id="ref-5">ULogin</_x003C_UserLogin_x003E_k__BackingField>
<_x003C_CustomerUserLogin_x003E_k__BackingField id="ref-6">CustUser</_x003C_CustomerUserLogin_x003E_k__BackingField>
<_x003C_Password_x003E_k__BackingField id="ref-7">ULPassword</_x003C_Password_x003E_k__BackingField>
</a1:SessionCreate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The question arises, how to do it normally, and what am I doing wrong?
I have some problems with the deserialization of my Soap response, i get an exception when try to deserialize with XmlSerializer class
Soap Data:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<IsWmsLoginCorrectResponse xmlns="http://pehade.be/">
<IsWmsLoginCorrectResult>
<UserId>int</UserId>
<LoginToken>guid</LoginToken>
<ErrorId>int</ErrorId>
<ErrorDescription>string</ErrorDescription>
</IsWmsLoginCorrectResult>
</IsWmsLoginCorrectResponse>
</soap12:Body>
</soap12:Envelope>
TokenInfo model:
public const string DefaultSoapNamespace = "http://pehade.be/";
//...
[XmlRoot("IsWmsLoginCorrectResponse", Namespace = Consts.DefaultSoapNamespace)]
public class TokenInfo : BaseSoapInfo
{
[XmlAttribute(AttributeName = "UserId", Namespace = Consts.DefaultSoapNamespace)]
public int UserId { get; set; }
[XmlAttribute(AttributeName = "LoginToken", Namespace = Consts.DefaultSoapNamespace)]
public string LoginToken { get; set; }
}
public class BaseSoapInfo
{
[XmlAttribute(AttributeName = "ErrorId", Namespace = Consts.DefaultSoapNamespace)]
public int ErrorId { get; set; }
[XmlAttribute(AttributeName = "ErrorDescription", Namespace = Consts.DefaultSoapNamespace)]
public string ErrorDescription { get; set; }
}
Parse Method:
public override T ParseSoap<T>(string resultSoap)
{
var document = XDocument.Parse(resultSoap);
var xmlSerializer = new XmlSerializer(typeof(T));
var soapBody = XName.Get("Body", Consts.DefaultSoapNamespace);
// Exception
var tokenInfo = (T)xmlSerializer.Deserialize(document.Descendants(soapBody)
.First()
.FirstNode
.CreateReader());
return tokenInfo;
}
Did I make the model correctly? Can there is other method to receive stream for XmlSerializer?
Update: Add exception details
System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00010] in :0
at DAL.SoapConverters.LoginSoapConverter.ParseSoap[T] (System.String resultSoap) [0x00031] in C:\Work\Projects\Apro\Other MDO\WarehouseMS\DAL\SoapConverters\LoginSoapConverter.cs:40 08-30 14:56:01.858 I/mono-stdout( 4702): System.InvalidOperationException: Sequence contains no elements
I think that the XmlAttribute(s) should be changed to XmlElement. For instance the UserId should be:
[XmlElement(Namespace = Consts.DefaultSoapNamespace)]
public int UserId { get; set; }
I am trying to add namespace during Xml Serialization. So far I have added some of them but I am unable to add custom namespace using Xml serializer.
So far I have achieved this
<?xml version="1.0"?>
<manifest xmlns:xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2e" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_rootv1p2" xsi:schemaLocation="http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xs" identifier="test" version="2">
<lom xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="test lom" xmlns="http://ltsc.ieee.org/xsd/LOM" />
<resource adlcp:scormtype="sco" />
</manifest>
This is my Code
Manifest Class
[Serializable]
[XmlRoot(ElementName = "manifest")]
public class Manifest
{
/// <summary>
/// manifest root node
/// </summary>
[XmlAttribute(AttributeName = "identifier")]
public string Identifier { get; set; }
[XmlAttribute(AttributeName = "version")]
public string Version { get; set; }
//[XmlAttribute(AttributeName = "adlcp", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
//public string Adlcp = "http://www.adlnet.org/xsd/adlcp_rootv1p2";
[XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string SchemaLocation = "http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xs";
[XmlElement(ElementName = "lom", Namespace = "http://ltsc.ieee.org/xsd/LOM")]
public Lom Lom { get; set; }
[XmlElement("resource")]
public Resource Resource { get; set; }
}
Lom Class
public class Lom
{
[XmlAttribute(AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string SchemaLocation { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.imsproject.org/xsd/imscp_rootv1p1p2e")]
public string Xsi = "http://www.w3.org/2001/XMLSchema-instance";
}
Resource Class
public class Resource
{
[XmlAttribute(AttributeName = "scormtype", Namespace = "http://www.adlnet.org/xsd/adlcp_rootv1p2")]
public string ScormType { get; set; }
}
My serialization function like this
using (FileStream fs = new FileStream(filePath, FileMode.Create))
{
var xmlSerializer = new XmlSerializer(typeof(Manifest));
var ns = new XmlSerializerNamespaces();
ns.Add("xmlns", "http://www.imsproject.org/xsd/imscp_rootv1p1p2e");
ns.Add("adlcp", "http://www.adlnet.org/xsd/adlcp_rootv1p2");
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlSerializer.Serialize(fs, data, ns);
fs.Close();
}
I need output like this.
<?xml version="1.0"?>
<manifest
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
identifier="test" version="2"
xmlns:adlcp="test"
xsi:schemaLocation="test location"
**xmlns="http://www.imsproject.org/xsd/imscp_rootv1p1p2"**>
<lom
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM lom.xsd"
xmlns="http://ltsc.ieee.org/xsd/LOM" />
<resource adlcp:scormtype="sco"/>
</manifest>
what I am doing wrong?
Simply add a namspace serializer
var xmlSerializer = new XmlSerializer(typeof(Manifest), "http://www.w3.org/2001/XMLSchema-instance");
var ns = new XmlSerializerNamespaces();
ns.Add("xmlns", "http://www.w3.org/2001/XMLSchema-instance");
xmlSerializer.Serialize(fs, data, ns);
and if data is defined as
Manifest data = new Manifest()
{ Identifier = "test", Version = "2", Adlcp = "test", SchemaLocation = "test location" };
data.Resource = new Resource() { ScormType="sco" };
with an attribute
[XmlAttribute(AttributeName = "adlcp", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Adlcp { get; set; }
you'll get xmlns:adlcp="test" in the output
Same thing for
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Xsi = "http://www.w3.org/2001/XMLSchema-instance";
As well as
ns.Add("adlcp", "http://www.imsproject.org/xsd/Manifest/Adlcp");
with
[XmlAttribute(AttributeName = "scormtype", Namespace = "http://www.imsproject.org/xsd/Manifest/Adlcp")]
public string ScormType { get; set; }
to get a possible adlcp:scormtype="sco"
Add a namespace to the root class too, for example
[XmlRoot(ElementName = "manifest", Namespace = "http://www.imsproject.org/xsd/Manifest")]
public class Manifest
I've been trying to de serialise an XML file into a list, but whatever I do, the list ends up with a count of 0.
I've been searching Stack like I normally do, tried all kinds of things, but am at my wit's end. What's going wrong here?
My XML:
<?xml version="1.0" encoding="utf-8"?>
<lijst>
<lijst_item>
<id>1</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>2</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>3</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
</lijst>
Lijst_item object:
[XmlType("Lijst_item")]
public class Lijst_item
{
[XmlAttribute("id", DataType = "int")]
public int ID { get; set; }
[XmlElement("naam")]
public string Name { get; set; }
[XmlElement("archived", DataType ="boolean")]
public bool isArchived { get; set; }
public Lijst_item()
{
}
public Lijst_item(int id, string name, bool archived)
{
this.ID = id;
this.Name = name;
this.isArchived = archived;
}
}
Code used to de serialise:
using (StreamReader sr = new StreamReader(sFile))
{
XmlSerializer deserializer = new XmlSerializer(typeof(List<Lijst_item>), new XmlRootAttribute("lijst"));
var Test = (List<Lijst_item>)deserializer.Deserialize(sr);
}
Convert xml to List by Deserialize in c#
Did not help me: Exactly what am I doing wrong? Is my XML malformed? My object? Can I for some reason not use a List?
Try this...
Usings...
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
Classes...(created using your XML at http://xmltocsharp.azurewebsites.net/)
[XmlRoot(ElementName = "lijst_item")]
public class Lijst_item
{
[XmlElement(ElementName = "id")]
public string Id { get; set; }
[XmlElement(ElementName = "naam")]
public string Naam { get; set; }
[XmlElement(ElementName = "archived")]
public string Archived { get; set; }
}
[XmlRoot(ElementName = "lijst")]
public class Lijst
{
[XmlElement(ElementName = "lijst_item")]
public List<Lijst_item> Lijst_item { get; set; }
}
Code...
string strXML = #"<?xml version=""1.0"" encoding=""utf-8""?>
<lijst>
<lijst_item>
<id>1</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>2</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>3</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
</lijst>";
byte[] bufXML = ASCIIEncoding.UTF8.GetBytes(strXML);
MemoryStream ms1 = new MemoryStream(bufXML);
// Deserialize to object
XmlSerializer serializer = new XmlSerializer(typeof(Lijst));
try
{
using (XmlReader reader = new XmlTextReader(ms1))
{
Lijst deserializedXML = (Lijst)serializer.Deserialize(reader);
}// put a break point here and mouse-over Label1Text and Label2Text ….
}
catch (Exception ex)
{
throw;
}
I use the following code to serialize my class as XML string:
AXMLItem rc = new AXMLItem();
rc.Attributes.Add(new Reports.ReportConfiguration.Questionnaire.FormObjectXMLItem.Attribute { Value = "ddddd" });
MemoryStream fw = new MemoryStream();
var serializer = new XmlSerializer(typeof(AXMLItem ));
using (StringWriter textWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(textWriter))
{
serializer.Serialize(xmlWriter, rc);
}
string myString = textWriter.ToString(); //This is the output as a string
}
that class definition
[XmlType(TypeName = "A")]
public class AXMLItem
{
[XmlType(TypeName = "B")]
public List<Attr> Attrs { get; set; }
[XmlType(TypeName = "C")]
public class Attr
{
[XmlText]
public string Value { get; set; }
}
public AXMLItem()
{
Attrs = new List<Attr>();
}
}
which gives me the following string
<?xml version="1.0" encoding="utf-16"?>
<A xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<B>
<C>ddddd</C>
</B>
</A>
but I need
<?xml version="1.0" encoding="utf-16"?>
<A xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<C>ddddd</C>
</A>
Keep in ming that there can be many <C>...</C> items. How to fix it ?
just add an XmlElement attribute to the collection property:
[XmlElement("C")]
public List<Attr> Attrs { get; set; }