Hello,
I have got a schema file "myschema.xsd" from my customer for which I must
create xml files. I used xsd.exe to create a class for the schema. I fill
an object for that class with data and serialize it.
My customer gave me an example xml file, how it should look like, and it
begins with
<?xml version="1.0" encoding="UTF-8"?>
<muma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="myschema.xsd">
<name>
....
=========
Question:
=========
How do I achieve to get the attributes
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" and
xsi:noNamespaceSchemaLocation="myschema.xsd" written in the serialization
process for my xml files?
Is there some kind of attribute I can stick to my xsd.exe generated class?
This is what my code looks like (in C#):
MemoryStream memoryStream = new MemoryStream();
Encoding encoding = Encoding.UTF8;
XmlTextWriter xmlWriter = new XmlTextWriter( memoryStream, encoding );
xmlWriter.Formatting = Formatting.Indented;
try
{
xmlWriter.WriteStartDocument();
XmlSerializer xmlSerializer = new XmlSerializer( muma.GetType() );
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add( string.Empty, string.Empty );
xmlSerializer.Serialize( xmlWriter, muma, ns );
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
PutToQueue( memoryStream );
}
finally
{
xmlWriter.Close();
}
Jürgen