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

Serialization - Removing Any Attributes in the root.

I am serializing a class I have and do not want any attributes in the root.
Here is what I have so far.

[System.Xml.Serialization.XmlRootAttribute("configu ration", Namespace="",
IsNullable=false )]
public class ShoppingList
{
....
}

which yields this
<?xml version="1.0" encoding="utf-8" ?>
- <configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

How do I get rid of the "xmlns:xsd" and the "xmlns:xsi". Also, I would like
to get rid of the "<?xml version..." at the top as well.

Thanks
Amy.
Nov 11 '05 #1
4 6410
Amy L. wrote:
How do I get rid of the "xmlns:xsd" and the "xmlns:xsi". Also, I would like
to get rid of the "<?xml version..." at the top as well.


Here is the trick how to get rid of redundant namespace declarations:
XmlSerializer serializer = new XmlSerializer(typeof(Test));
Test t = new Test();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(Console.Out, t, ns);

But getting rid of xml declaration can be somewhat troublesome and above all
it's actually bad idea, which can result in severe encoding problems. Why do
you need to remove it?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
I wanted to get rid of the xml decleration because I am working on a
application config file. Essentially, I have a configuration tool an admin
runs that creates the application.exe.config file and based on microsoft's
examples none of these configuration files have the xml decleration.

Amy.

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Amy L. wrote:
How do I get rid of the "xmlns:xsd" and the "xmlns:xsi". Also, I would like to get rid of the "<?xml version..." at the top as well.
Here is the trick how to get rid of redundant namespace declarations:
XmlSerializer serializer = new XmlSerializer(typeof(Test));
Test t = new Test();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(Console.Out, t, ns);

But getting rid of xml declaration can be somewhat troublesome and above

all it's actually bad idea, which can result in severe encoding problems. Why do you need to remove it?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
Amy L. wrote:
I wanted to get rid of the xml decleration because I am working on a
application config file. Essentially, I have a configuration tool an admin
runs that creates the application.exe.config file and based on microsoft's
examples none of these configuration files have the xml decleration.


Don't worry, config files are well-formed XML files and of course they
can have XML declaration.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4
Amy,

The document declaration really shouldn't mess up anything ... if it does
then you should change the parser you're reading the document with.
Nevertheless, if you really need to remove the declaration, check out this
[0] sample on gotdotnet.

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

[0]
http://www.gotdotnet.com/Community/U...b-3a0a9e13bbe3

"Amy L." <am**@paxemail.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
I wanted to get rid of the xml decleration because I am working on a
application config file. Essentially, I have a configuration tool an admin runs that creates the application.exe.config file and based on microsoft's
examples none of these configuration files have the xml decleration.

Amy.

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Amy L. wrote:
How do I get rid of the "xmlns:xsd" and the "xmlns:xsi". Also, I
would
like to get rid of the "<?xml version..." at the top as well.
Here is the trick how to get rid of redundant namespace declarations:
XmlSerializer serializer = new XmlSerializer(typeof(Test));
Test t = new Test();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(Console.Out, t, ns);

But getting rid of xml declaration can be somewhat troublesome and above

all
it's actually bad idea, which can result in severe encoding problems.

Why do
you need to remove it?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel


Nov 11 '05 #5

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

Similar topics

2
by: Daniel Faensen | last post by:
As a good OO programmer that I hopefully am I prefer to implement against interfaces rather than classes. This is especially useful when it comes to multiple inheritance which is as you know an...
4
by: Alex | last post by:
It seems that XML Serializatoin automatically puts certain XSD attributs in the root node. How can I control the root node attributes emitted to something more custom so I can preserve my schema...
3
by: Mark | last post by:
Hello, What I am trying todo is use .NET serialization to take a Guid property that is an attribute in the XML document and have its output to be the same as...
0
by: Joe Rizla | last post by:
I am using XML Serialization to output the IBuySpy tabs data. I have used System.Xml.Serialization to serialize an array of a class called TabStripDetails. Using attributes I rename the resultant...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
0
by: rein.petersen | last post by:
Hi All, Some of you may have encountered complications when trying to serialize an object derived from CollectionBase (implementing ICollection or IEnumerable). Specifically, the...
1
by: parag.gadkari | last post by:
Can a name value collection be serialized as attributes to the Xml element of class containing this name value collection? For eg. if a class pControl: public class pControl { ........
3
by: Paulo Morgado [MVP] | last post by:
Hi all ..NET Framework 1.1 I have created several types that are serailized to XML as strings. Someting like this: public struct MyInt32 : IXmlSerializable { int value;
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.