For your first question, one way to do it is to derive from
System.Xml.XmlT extWriter, and simply provide a "null" implementation of
WriteStartDocum ent().
public class XmlTextWriterFo rmattedNoDeclar ation :
System.Xml.XmlT extWriter {
public XmlTextWriterFo rmattedNoDeclar ation (System.IO.Text Writer w) :
base(w) { Formatting= System.Xml.Form atting.Indented ;}
public override void WriteStartDocum ent () { } // suppress
}
Then, something like this
ser = new XmlSerializer(t hing.GetType()) ;
sw = new StringWriter();
System.Xml.XmlW riter xmlWriter = new
XmlTextWriterFo rmattedNoDeclar ation(sw);
ser.Serialize(x mlWriter, 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.TextW riter. eg
ser = new XmlSerializer(t hing.GetType()) ;
ser.Serialize(n ew
XmlTextWriterFo rmattedNoDeclar ation(System.Co nsole.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.XmlSche maForm.Qualifie d, eg
Visual Basic .NET Code
<System.Xml.Ser ialization.XmlE lementAttribute (Form:=System.X ml.Schema.XmlSc h
emaForm.Qualifi ed)> _Visual C# .NET Code
[System.Xml.Seri alization.XmlEl ementAttribute( Form=System.Xml .Schema.XmlSche
maForm.Qualifie d)]
for doc on this, see XmlElementAttri bute
http://msdn.microsoft.com/library/en...sFormTopic.asp
-Dino
"Kevin C" <kc@noneya.co m> wrote in message
news:uI******** ********@TK2MSF TNGP11.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 "elementFormDef ault". I don't see anywhere in a class any references
to this attribute. I need the elements to be qualified.
Kevin