468,771 Members | 1,922 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

How to serialize with xsi:noNamespaceSchemaLocation attribute?

jr
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
Nov 11 '05 #1
0 4082

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Balaji V | last post: by
3 posts views Thread by Mark Jerde | last post: by
1 post views Thread by Craig | last post: by
2 posts views Thread by =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post: by
3 posts views Thread by Samuel | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.