473,394 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 4483

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: johnsocs | last post by:
How do you validate the following XML document, I'm having problems with element 'one' with the attribute xsi:type="xsd:string" <?xml version="1.0" encoding="UTF-8"?> <zero...
0
by: Lindy | last post by:
I'm using VB .Net and am new to XML. I need to create an XML file with the following lines: <?xml version="1.0" encoding="UTF-8" ?> - <HC_DATA...
0
by: Lindy | last post by:
I'm using VB .Net and am new to XML. I need to create an XML file with the following lines: <?xml version="1.0" encoding="UTF-8" ?> - <HC_DATA...
1
by: Balaji V | last post by:
Hi, I am creating C# calsses to seralize and deserialize based on xsd. When defining the classes to do seralization i need to specify the schema for the reference. Typically my class...
1
by: AP | last post by:
Hi, I'm getting the following error trying to validate an xml document against a schema: The 'xsi:noNameSpaceSchemaLocation' attribute is not declared My xml file looks like this: <?xml...
3
by: Mark Jerde | last post by:
I've been looking through MSDN, books and googling for a couple hours but haven't found the solution yet. I'm using CSharp in VS .NET 2003. I'm trying to use XmlDocument to save XML files that...
1
by: Craig | last post by:
Hi there, I'm generating an XML script using ElementTree which has the following attributes in the root element: <CANmessages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
2
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Hello guys, I was wondering if it was possible to disregard the xsi:noNamespaceSchemaLocation. For validation it's obviously easier to have it point to say a local directory but the final...
3
by: Samuel | last post by:
I use the following code to create the XML from a class object Dim serialize As New System.Xml.Serialization.XmlSerializer(GetType(XYZObject)) serialize.Serialize(obWtiter, obObject) But I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.