For your first question, one way to do it is to derive from
System.Xml.XmlTextWriter, and simply provide a "null" implementation of
WriteStartDocument().
public class XmlTextWriterFormattedNoDeclaration :
System.Xml.XmlTextWriter {
public XmlTextWriterFormattedNoDeclaration (System.IO.TextWriter w) :
base(w) { Formatting= System.Xml.Formatting.Indented;}
public override void WriteStartDocument () { } // suppress
}
Then, something like this
ser = new XmlSerializer(thing.GetType());
sw = new StringWriter();
System.Xml.XmlWriter xmlWriter = new
XmlTextWriterFormattedNoDeclaration(sw);
ser.Serialize(xmlWriter, thing);
then the output you want is sw.ToString().
In place of the StringWriter, you could direct your output to
System.Console.Out, which is also a System.IO.TextWriter. eg
ser = new XmlSerializer(thing.GetType());
ser.Serialize(new
XmlTextWriterFormattedNoDeclaration(System.Console .Out), thing);
then the output goes to stdout.
--
For your 2nd question, you can decorate the properties or fields with an
XmlElement attribute, specifying
Form=System.Xml.Schema.XmlSchemaForm.Qualified, eg
Visual Basic .NET Code
<System.Xml.Serialization.XmlElementAttribute(Form :=System.Xml.Schema.XmlSch
emaForm.Qualified)> _Visual C# .NET Code
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSche
maForm.Qualified)]
for doc on this, see XmlElementAttribute
http://msdn.microsoft.com/library/en...sFormTopic.asp
-Dino
"Kevin C" <kc@noneya.com> wrote in message
news:uI****************@TK2MSFTNGP11.phx.gbl...
Is there a way to suppress the rendering of the xml processor instruction
when using the XmlSerializer? I do not want "<?xml version="1.0"?>" to be
written out. Also, do classes generated from XSD.EXE care about the value
of "elementFormDefault". I don't see anywhere in a class any references
to this attribute. I need the elements to be qualified.
Kevin