devo creare un file XML con tutti gli elementi come prefisso, come questo:XmlSerializer Producing XML With No Namespace Prefix
<ps:Request num="123" xmlns:ps="www.ladieda.com">
<ps:ClientId>5566</ps:ClientId>
<ps:Request>
Quando ho serializzare il mio scopo, C# è intelligente e fa questo:
<Request num="123" xmlns="www.ladieda.com">
<ClientId>5566</ClientId>
<Request>
Questo è buono, perché la ps: non è necessario.
Ma c'è un modo per forzare C# per serializzare tutti i prefissi?
Il mio codice serialize è questo (per oggetto in entrata pObject):
String XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(pObject.GetType());
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, pObject);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
return XmlizedString;
private String UTF8ByteArrayToString(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedString = encoding.GetString(characters);
return (constructedString);
}
BTW, non è dimenticare lo spazio dei nomi. Il tuo spazio dei nomi è serializzato correttamente. Semplicemente non sta usando un prefisso, il che ha senso, dal momento che non gli hai detto un prefisso da usare. –