471,117 Members | 1,171 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,117 software developers and data experts.

How to serialize with xsi:noNamespaceSchemaLocation attribute?


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"

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;
XmlSerializer xmlSerializer = new XmlSerializer( muma.GetType() );
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add( string.Empty, string.Empty );
xmlSerializer.Serialize( xmlWriter, muma, ns );
PutToQueue( memoryStream );
Nov 11 '05 #1
0 4218

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.