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


 0
kc347 (2)
8/11/2004 6:26:04 PM
dotnet.xml 7266 articles. 0 followers.

2 Replies
708 Views

Similar Articles

[PageSpeed] 8

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-us/cpref/html/frlrfSystemXmlSerializationXmlElementAttributeClassFormTopic.asp

-Dino

"Kevin C" <kc@noneya.com> wrote in message
news:uI%236qC9fEHA.3428@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
>
>


 0
dinoch1 (221)
8/11/2004 7:41:31 PM
Thanks, Dino.

"Dino Chiesa [Microsoft]" <dinoch@online.microsoft.com> wrote in message
news:%23%237k1s9fEHA.1656@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-us/cpref/html/frlrfSystemXmlSerializationXmlElementAttributeClassFormTopic.asp
>
> -Dino
>
>
>
> "Kevin C" <kc@noneya.com> wrote in message
> news:uI%236qC9fEHA.3428@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
> >
> >
>
>


 0
kc347 (2)
8/11/2004 8:04:02 PM

Similar Artilces:

XML datasource
SSBoYXZlIGEgVlMgMjAwNSBiZXRhLg0KSG93IEkgY2FuIGNyZWF0ZSBhIFhNTCBkYXRhc291cmNl IGluIGRlc3Vnbi10aW1lPw0KDQotLSANClN0YW5pc2xhdyBUcmlzdGFuDQpJUCBQcm90ZWN0aW9u DQpLeWl2LCBVa3JhaW5lDQpFLW1haWw6IGFkbWluQHplc3RhZC5jb20NCldFQjogd3d3Lnplc3Rh ZC5jb20= VGhhbmtzLCBzb2x1dGlvbiBmb3VuZDogQWRkLT5OZXcgSXRlbS0+RGF0YXNldA0KDQotLSANClN0 YW5pc2xhdyBUcmlzdGFuDQpJUCBQcm90ZWN0aW9uDQpLeWl2LCBVa3JhaW5lDQpFLW1haWw6IGFk bWluQHplc3RhZC5jb20NCldFQjogd3d3Lnplc3RhZC5jb20NCiJTdGFuaXNsYXcgVHJpc3RhbiIg PHN0YXM3NzVAaS5jb20udWE+INPPz8Ldycwv08/Pwt3JzMEg1yDOz9fP09TRyCDTzMXE1cDdxcU6 IG5ld3M6ZXNTVkxsS2ZGSEEuMjQyNEBUSzJNU0ZUTkdQMDkucG...

I have created a XML File With XmlTextWriter and the result is : <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Configuration> <Settings> <DbName>DoxWork</DbName> <PathDB>C:\Documents and Settings\v.savino\Desktop\</PathDB> <DbServerName>Server</DbServerName> </Settings> </Configuration> Use XmlTextReader for read XML File.. This is my code : Do While XReader.Read If XReader.NodeType = XmlNodeType.Element Then msgbox XReader.LocalName & " " & ...

Best Practice
Hey all, I have an XML doc that I read into a SQL Server database from an integration feed.... ----------------XML snippet ---------------- <?xml version="1.0" encoding="us-ascii"?> <!--Product data from JDEdwards--> <Root> <Root RvcDate="2004-02-03" RcvTime="14.16.03.795135"> <Product> <File>1234A</File> <Library>XCOMM</Library> <ActionCode>A</ActionCode> <TransDate>2004-02-03</TransDate> <TransTime&g...

Read xml file with multiple elements
I have the following xml file that I want to read in using vb.net 2003: <dordivision name="district 1" propname="District 1"> <printer id="location11" duplex="false">Location 11</printer> <printer id="location12" duplex="true">Location 12</printer> <printer id="location13" duplex="true">Location 13</printer> <printer id="location14" duplex="false">Location 14</printer> </dordivision> <dordivision name="dis...

Writing DataSets to XML
Hello I have a DataTable where one of the columns contains XML, when I add it to a DataSet and call WriteXML it automaticaly encodes the XML (e.g. < becomes &lt;) is there an easy way to prevent this encoding from happening? Currently I am having to parse the resultant XML amd swap the encoded values for the original XML. This works ok and produces valid XML but I'm sure its not the best way to do it. Thanks for any ideas All the best Dan Manchester Uni. UK Try microsoft.public.dotnet.framework.adonet <danpowley@gmail.com> wrote in message news:1123175910.205480.302900...

Update XML config file with treeview nodes
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file exists just to sort of synchronize them by changing the xml nodes attribute(s). somehow i always catch an exception "blabla has an invalid token" but i cannot find a solution for this. maybe someone of you people can tell me how to do this correctly. thanks in advance! =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=...

OWA and viewing xml files as txt file
Hi, We are trying to view download xml files renamed to txt from OWA. We are able to download the file; however, the content of the file is omitted. We already determined that the virus scan does not remove the contents from the txt file. can anyone asist. Thank you very much. Tommy ...

DataSource wrong in all .xml reports
For some reason, the DataSource name in all my reports is wrong (or maybe I'm just ignorant?). Shouldn't the DataSource Name="Company_Name_MSCRM", ie the SQL database name? Additionall, why does "Adventure_Works_Cycle_MSCRM" show up as the initial catalog? I found in VS, if i did a find/replace for all these DataSource Names, I could get the report to run properly in VS. Is this the fix for this - to find/replace the datasource name in all the reports? I've tried running a repair on CRM and publishing the reports to no avail <DataSources> <...

Loosing parameters via xml control
Howdy I have an xslt that accepts parameters. In my code I set these paramaters and pass them to the xml control to transform and display the xml according to the xslt. When I throw the form directly into the response.write it shows my paramaters just fine. Since I altered the code to use the Xml Control, these parameters are not received by the Xslt upon transformation via the xml control. Here is my code. '*CTE00 - Throw the Document into a xml navigator. '************************************************* NavApproveCondition = DocApproveCondition.CreateNaviga...

XML Signature in Web Services.
According to the technical article "Understanding XML Digital Signature", the author mentions that the "At this point, we know how to refer to content, transform and hash it, and create a signature that covers (protects) that content. Recall that content is protected by using indirection: the ds:SignatureValue covers the ds:SignedInfo, which contains ds:References that contain the digest values of the application data. Change any of those things, and the chain of math computations is broken, and the signature won't verify." I have tried to sign a SOAP XML and ha...

Word 2007 XML to HTML
I'm not sure this is the correct locqation to post this question but I have already posted similar question in Office news group (without response) I am using VS2005 to create a solution for Word 2007. This version of Word no longer supports HTML as previous versions did. To maintain compatability with previous solution written for previous versions of Word, I need the HTML content of a document that Word previously acquired with MyStr = ActiveDocument.HTMLProject.HTMLProjectItems(1).Text Word produces an XML file using "activedocument.content" so I'm thinking that m...

Getting a strange error when I try to view an XML file from VS.NET
The error message that I'm getting is: "Cannot find the file 'C:\text.xml' (or one of its components). Make sure the path and filename are correct and that all required libraries are available". I've attached the file that I have saved at C:\text.xml. It's a simple XML file that I threw together for testing. But it's giving me that error. Does anyone have any idea why I might be getting this, and (more importantly) how I can fix it? Thanks! -Scott begin 666 test.xml M/#]X;6P@=F5R<VEO;CTG,2XP)R!E;F-O9&EN9STG=71F+3@G(#\^#0H\<75O M=&4^#0H\5&...

Using IM with XML source adapter & VB scripting
How can you reference a field in the XML source with VB? I tried to qualify the entire path specifying the nodes ex. SourceFields ("APInvoices.InvoiceList.Invoice.InvoiceItems.LineItem.Amount) but that was not recognized by IM. Any suggestions would be helpful! ...

who controls the encoding when transforming xml?
I do a transform of an xml document into another xml using XslTransform. In my xsl file, I specify using <xsl:output encoding="utf-8"/>. However, when my transform is done, the resulting xml is in utf-16. What gives? Anyone? Your Xml doc is probably UTF-16 encoded. You might want to check what encoding the Xml doc was saved with. Maybe even try saving it as UTF-8 - in notepad say. Any joy? Steven Founder, http://venturetogether.com "Jiho Han" <jiho.han@infinityinfo.com> wrote in message news:#aSeTVP7DHA.2432@TK2MSFTNGP10.phx.gbl... > I do a transform ...

Create XML Node / Element from a Shema
hi, i have a question, is it possible to create a XML Node or Element from a shema? i have a Shema and would like to create a node with one line of code. my node has some attributes and it is borring to write statements for creating attribute for every node. i am using c#. thanks ...

pluggable xml
Hello, In Java the XML DOM is interface based, hence pluggable implementations. In ..NET it's been in from the start of course and is class based, but I notice there appear to be some alternate implementations appearing, eg xerces has been ported, and Saxon 8 .NET for XSLT 2.0 support (which if it's like Java will have a DOM implementation optimised for the XSLT processor). If I want to provide a public API which takes an XML Document (DOM), is there a relatively clean way to allow pluggable DOM implementations, all that occurs to me initally is to write/steal DOM interfaces and prov...

deprecated XML technologies?
XML is a huge area with so many related technologies, xpath,xsl, etc, have any been deprecated or replaced with something better? For example, I believe that DTD's are no longer popular (although my tiny mind has already forgotten the new sexier way of specifying a schema). As you can tell, it's not an area I'm overly familar with. I'm looking at some greenfield projects so I'd rather concentrate on what is currently considered good practice. Many thanks. *** Sent via Developersdex http://www.developersdex.com *** ian wrote: > XML is a huge area with so many ...

Supress error message
I am using the formla: =average(b35:b47) to put the average of cells b35 to b47 into cell b48. Is there a way to avoid the cell b48 showing the result : #DIV/0! when I have no entries in the range of aforementioned cells? Thank you Jim try this ARRAY formula which must be entered/edited with CSE (ctrl+shift+enter) =AVERAGE(IF(C1:C5<>"",C1:C5)) -- Don Guillett SalesAid Software donaldb@281.com "Jim Anderson" <janderson@wi.rr.com> wrote in message news:5R6rd.2025\$NO5.1347@twister.rdc-kc.rr.com... > I am using the formla: > =average(b35:b47) > to put...

hirrerachy records in XML
Hi, I am a newbie in XML and just wondering if XML support the hirrerachy records. For example an item master which has multiple UOM attached to it. Is it possible to save this data in XML format? I have googled it on web and couldnt find a clear cut answer. Thanks Vijay Mishra Dataset has a method as "WriteXML", will help you write to xml file after sorting or what ever you want... HTH -- Every thing is perfect, as long as you share!!! "Vijay Mishra" wrote: > Hi, > > I am a newbie in XML and just wondering if XML support the hirrerachy > records...

excel to xml
Hello I am trying to figure this out. Yes there is some new feature in excel 2003 according to the websites that I browsed thro' It is about transforming a excel spreedsheet into Xml with the syntax you wanted instead of repeating cut and paste of the syntax in an Xml file. I was reading in msdn that excel 2003 has these features but I have no clue. When I give file save as in an excel file .I have many features I can save as to,so when I select save as xml data .I can include an xml map to map to the excel fields but after that it doesn't go forward for me. I nee...

How to find the custom xml tags in a workbook
We have work books where a user designs a layout using a xsd schema, & we populate the data in those fields. Problem is I need to find where each of the custom xml ( from the schema) is placed, is there a way to find it, given the element name or even get all the elements & iterate thru them. Cyril ...

C++ VS.NET 2003 simple XML sample problem.
I'm going from VS 6.0 to VS .NET 2003. I'm converting a project and can't get it to compile. I've created a small Win32 console app that reproduces the compiler error. This has got to be something dumb. Please help. #import <msxml.dll> int _tmain(int argc, _TCHAR* argv[]) { IXMLDOMDocumentPtr Xml; Xml->createElement(_T("Tagname")); return 0; } The compiler error is: error C2660: 'IXMLDOMDocument::createElement' : function does not take 1 arguments When I go to the definition of createElement, it shows three types: inline IXMLDOMEle...

Instructions please in setting up Outlook
I have MS Outlook 2003 on my computer, and I would like to set it up and import the messages from my Outlook Express. I have been getting "Message could not be displayed" errors when using the "Find" feature in OE, and I was wondering if Outlook had the same problems with folder/file sizes. Thanks in advance, Sheana sheana wrote: > I have MS Outlook 2003 on my computer, and I would like to set it up and > import the messages from my Outlook Express. I have been getting "Message > could not be displayed" errors when using the "Find" fea...

On POS (not RMS) Instructions for Changing Noninventory Item, Price, Cost, and Volume
We drop ship noninventory items to customers, and when the price, cost, or capacity of an item changes, we want to change it so it is reflected accurately on invoices. However, when we attempt to change the cost, price, and description, a message pops up stating "The item description is already in use." Of course it's already in use, we just want to edit it. Nothing else has changed, same Item Number, same Department, same Category; we're just not permitted to edit it. For example, if the Item Description were "Coke," and we attempt to change the Item Descripti...

Exporting .xml from Money 2002
I am unable to export an account transactions report that shows splits (one option in customization) in .xml format. I successfully created an investment transactions report in .xml, and can create an account transactions report as long as I don't include splits. Very strange ...