XmlSerializer with a xmlns specified

G

Guest

Hi there,
any anyone answer this simple question

i have an xml file
<?xml version="1.0"?>
<globaltrace xmlns:"http://www.something.org">
.. . .
</globaltrace>

Now I have a class used for serialization
[Serializable]
[XmlRoot(ElementName = "globaltrace", Namespace="http://www.something.org")]
public class GlobalTraceConfig
{
....
}

Basically I can deserialize as follows
GlobalTraceConfig gtc = null;
using (System.IO.FileStream fs = new System.IO.FileStream(fileName,
System.IO.FileMode.Open))
{
gtc = (GlobalTraceConfig)m_formatter.Deserialize(fs);
}

This is fine, but
how can i serialize so that i get
<<?xml version="1.0"?>
<globaltrace xmlns:"http://www.something.org">

I've tried the following
using (System.IO.FileStream fs = new System.IO.FileStream(fileName,
System.IO.FileMode.Create))
{
//XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
//ns.Add(string.Empty, "www.bfa.ch");
//m_formatter.Serialize(fs, this, ns);
m_formatter.Serialize(fs, this);
}

it only works if i add the namespace (uncomment code) and also remove the
Namespace="http://www.something.org")] from my xml root

any ideas anyone?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top