XmlSerializer - XmlWriter to string, works not with namespaces

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,
my target is to write a xml file.

<?xml version="1.0" encoding="iso-8859-1"?>
<Control xsi:noNamespaceSchemaLocation="control-1.0.xsd" locale="english" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<controlRequest requesttime="2017-09-05T11:03:32+02:00" requestID="9779" order="3888492">
<properties>
<orderProperties>
<orderProperty name="nominalValue1"/>
<orderProperty name="nominalValue2"/>
<orderProperty name="nominalValue3"/>
<orderProperty name="nominalValue4"/>


I want to use XmlSerializer.


/// <remarks/>
[XmlType(AnonymousType = true)]
[XmlRoot(Namespace = "", IsNullable = true)]
public partial class control
{
private controlControlRequest controlRequestField;
private string localeField;

XmlWriterSettings writerSettings = new XmlWriterSettings { OmitXmlDeclaration = false, Indent = true, Encoding = Encoding.GetEncoding("ISO-8859-1") };
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("xsi", "control-1.0.xsd");
//..
//..
using (StringWriter textWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(textWriter, writerSettings))
{
serializeRequest.Serialize(xmlWriter, test);
}
request = textWriter.ToString();
}


I found this, but is not working. The namespaces are not written.
XML Namespaces
Can someone give me a solution? Thanks in advance.
With best regards Markus

Continue reading...
 
Back
Top