serialize disable encoding attribute

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

in my Application i have the need to get an XML Declaration without the
Encoding Tag.

Actual i get this declaration: <?xml version="1.0" encoding="utf-8"?>

I need this: <?xml version="1.0"?>

Im using the following Code to produce the XML File:

XmlSerializer XmlS = new XmlSerializer( typeof( AccessRequest ) );
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("","");
TextWriter TWriter = new StreamWriter( Server.MapPath("list.xml") );
XmlS.Serialize( TWriter, AccReq, ns);
TWriter.Close();

Please help me with this ... i'm going crazy
 
Pascal.Schicht said:
Hi!

in my Application i have the need to get an XML Declaration without
the Encoding Tag.

Actual i get this declaration: <?xml version="1.0" encoding="utf-8"?>

I need this: <?xml version="1.0"?>
[...]

Hm... do you realize that both declarations are equivalent?
 
Yes, but in this case i need to do it without the encoding attribute because
i'm working on a solution to transfer shipping data to ups. the ups server
accept the xml file only without the encoding attribute.

my application is so far based on the XmlSerializer and i don't want to do a
work around and delete the encoding attribute "by hand".

i'm still need help ... i will be happy for every suggestion

apologize my poor english!

Joerg Jooss said:
Pascal.Schicht said:
Hi!

in my Application i have the need to get an XML Declaration without
the Encoding Tag.

Actual i get this declaration: <?xml version="1.0" encoding="utf-8"?>

I need this: <?xml version="1.0"?>
[...]

Hm... do you realize that both declarations are equivalent?
 
Pascal.Schicht said:
Yes, but in this case i need to do it without the encoding attribute
because i'm working on a solution to transfer shipping data to ups.
the ups server accept the xml file only without the encoding
attribute.

Maybe they should use a *real* XML processor...
my application is so far based on the XmlSerializer and i don't want
to do a work around and delete the encoding attribute "by hand".

i'm still need help ... i will be happy for every suggestion

I'm not sure if there's a clean way to suppress the encoding attribute
(probably using XmlTextWriter), but if all fails, you can serialize
your object to a string and remove the encoding manually :-/

Cheers,
 
Use XmlDeclaration, besides from removing manually the enconding this i think
is the other way i've found to change it
 
Back
Top