473,397 Members | 2,099 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,397 software developers and data experts.

XmlSerializer with a xmlns specified

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?
Jul 5 '06 #1
1 3336
it's ok,
namespaces strings didn't match.

tnx 4 looking though

"brian" wrote:
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?
Jul 5 '06 #2

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

Similar topics

3
by: Integer Software | last post by:
Hi. I have a really simple set of classes that writes 2 pathnames to a xml file. I can write the default ok. Then if I change 1 pathname to a shorter one, then rewrite the xml file, the remains...
5
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not...
8
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
2
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
2
by: Daniel Lidström | last post by:
Hi, the class looks like this: public __gc class LandXML { public: ... };
3
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
0
by: William Stacey [MVP] | last post by:
Had a method that got some string info from mp3 tags in N files and serializes this class and deserializes at other side. Works ok except sometimes get chars that choke the XmlSerializer. After...
1
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
0
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.