473,387 Members | 1,510 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,387 software developers and data experts.

How to Supress XML Processor instruction

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
Nov 12 '05 #1
2 3770
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

Nov 12 '05 #2
Thanks, Dino.

"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
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


Nov 12 '05 #3

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

Similar topics

1
by: LRW | last post by:
I'm creating a simple reply form, and if a form item isn't answered I get an error: "Notice: Undefined index: rb_amntspent in c:\inetpub\wwwroot\mackinaw\survey.php on line 36" even if in the...
1
by: roderik | last post by:
How do I supress the output generated from each psycopg command: >>> import psycopg initpsycopg: initializing psycopg 1.99.10 typecast_init: initializing NUMBER .. .. microprotocols_add:...
3
by: Alex | last post by:
I stumbled upon this while developing a custom XPathNavigator. It appears that copy action for attributes is broken in the .net framework XSLT processor. The intent was to just copy the entities...
1
by: David | last post by:
I have a custom control that contains a class that Inherits the panel control. I am trying to catch a keydown event in this class and then supress it from the rest of the control as well as the...
3
by: JG | last post by:
Hi all, I have a simple aspx page. On the page there is only one button. When I click on the button, the event sequence is Page_Load, Button1_click and Page_PreRender. How do I supress the...
10
by: WannaKatana | last post by:
I am just wondering why, with nothing else running and executing an update query against a very large table, does Access seem to be causing less than 10% processor usage. Then it says "There is not...
168
by: broeisi | last post by:
Hello, Is there a way in C to get information at runtime if a processor is 32 or 64 bit? Cheers, Broeisi
2
by: khani | last post by:
Hi i have following situation in cystal report in detail section i have a field say name.now i have five duplication record like this zahid zahid zahid zahid
3
by: aha | last post by:
Dose anyone know of a cross-platform method for determining the vendor of a processor? Under linux I can check /proc/cpuinfo. What I'd like to be able to do is determine if a processor is AMD or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.