473,587 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "elementFormDef ault". 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 3777
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

Nov 12 '05 #2
Thanks, Dino.

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


Nov 12 '05 #3

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

Similar topics

1
4519
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 code I allow for an unselected item. (Code at the bottom here.) It works fine otherwise. Now in the past I've made a change to php.ini to repress errors, but for this project I don't have access to the php.ini.
1
1543
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: cast 0x46dd20 for (bool, ?) initpsycopg: module initialization complete
3
1748
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 and attributes from the source XML into the output using simple "identity" like XSLT: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/>
1
3533
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 form that hosts the control. The problem I am running into is that the form that hosts the control will respond to the keydown event event. Any ideas what I am missing? Some source code to help:
3
3140
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 PreRender event? I know if I call Server.Transfer or Reponse.Redirect in the Button1 click event, the page prerender event will not occur. Thanks. Jie
10
6993
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 enough disk space or memory to undo the changes". I have 2 gb RAM, Core 2 duo e6300 processor and plenty of disk space. Why doesn't Access peg the CPU? Joel
168
7165
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
1333
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
1338
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 Intel, so that I can use the appropriate numerical libraries for my application. Regards, Aquil
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.