How to XmlSerialize directly into XmlDocument

Hi

this approach works IF the target document is empty:

XmlDocument doc = new XmlDocument();
XPathNavigator nav = doc.CreateNavigator();
XmlSerializer ser = new XmlSerializer(typeof(string));
using (XmlWriter writer = nav.AppendChild()) {
    ser.Serialize(writer, "works ok");
}//using

but if I want to insert the xml into an existing element:

XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateElement("Root"));
XPathNavigator nav = doc.FirstChild.CreateNavigator();
XmlSerializer ser = new XmlSerializer(typeof(string));
using (XmlWriter writer = nav.AppendChild()) {
    ser.Serialize(writer, "fails");
}//using

giving message "WriteStartDocument cannot be called on writers created
with ConformanceLevel.Fragment."

Does anybody know of a workaround?
0
first101 (1)
9/27/2010 4:44:31 PM
dotnet.xml 7266 articles. 0 followers. Follow

0 Replies
798 Views

Similar Articles

[PageSpeed] 21

Reply:

Similar Artilces:

Goes directly in deleted item.
This is very odd. Someone is not working for us anymore. I've disable is account in User Manager and Changed the Primary Windows Nt Account in Exchange) I don't know if its related to that, but know all the emails sent to that recipient will directly go in is Deleted Items in Outlook! I've tried to give back the rights, but didn't help (on NT4 with Exchange 5.5) Mathieu not related check settings on client side (rules?) D. "Mathieu" <sdfdas@sdfs.com> wrote in message news:uyh8CrL9DHA.4060@tk2msftngp13.phx.gbl... > This is very odd. > Someone is no...

XmlSerializer Collection with Collections
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different attributes, all share a base set of 4, one of the question types can have children with <option> elements, this is how the xml looks after serialization.... If you notice there is an extra <SelectionList> around the <option>'s in the final <question>, how can I write my class so I don't have this extra <SelectionList> element....my class follows, you ...

Health savings account and direct deposit
I just started a Health savings account for employees for insurance benefits. The employee is having a payroll deduction that I will direct deposit w/ payroll or would like to. I also am matching some of their contribution that I would also like included in the payroll direct deposit. How do I set this up and go about getting it on the employee's check and direct deposited to their accounts? Hi Carmie, I have done this for several clients. I created a pay code FSA with a type of Other. Mark the code not subject to taxes as that applies. Assign the code to the emp...

how do i plot a rose diagram to show frequency of wind direction
can i use excel or another program in microsoft to do this? Hi Kathryn, Get a wind rose for Excel here http://edferrero.m6.net/content/windrose.zip Ed Ferrero http://edferrero.m6.net "kathryn" <kathryn@discussions.microsoft.com> wrote in message news:71874D4A-0D49-4490-BAE1-2C74F9E876FC@microsoft.com... > can i use excel or another program in microsoft to do this? ...

XmlSerializer
I'm having a basic problem with the XmlSerializer & i'm at my wits end trying to sort it out i have a basic clas <Serializable()> Class Tes Public Name as Strin End Clas when this serializes i wan <Test><Name>Value</Name></Test the problem is if i use the XmlSerializer clas Dim t as Tes t.Name="Value Dim sb As New StringBuilde Dim sw As New StringWriter(sb Dim Serializer As New XmlSerializer(Message.GetType Serializer.Serialize(sw, t Serializer = Nothin Console.Write(sb.ToStr...

How can I change worksheet direction from right to left
I want to change the direction of the work sheet in Excel 2007 from left to right and vice versa If you mean you want to change the direction of the cursor on Enter, then click on the round logo top left, select Excel options, select Advanced, and change the direction to Left, Right, Up or Down as you desire. -- HTH Kassie Replace xxx with hotmail "Haitham" wrote: > I want to change the direction of the work sheet in Excel 2007 from left to > right and vice versa I believe the only way is to go through Microsoft Office Tools and make the setting ...

XmlSerializer and shared objects (or How to generate IDREFs using XmlSerializer)
This is a multi-part message in MIME format. ------=_NextPart_000_007F_01C34AC1.11D4FB20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am trying to find a solution that will allow me to use XmlSerializer = to serialize/deserialize a collection of objects where a given object is = shared between two or more other objects, and not create duplicate XML = representations of the shared object, but instead use IDREFs to refer to = the shared object. The XML I'm trying to produce is as follows (where "href" is an IDREF): <...

XmlSerializer and inherited objects
Hi I have a hirachy of classes which are Message(base), then FileMessage and ChatMessage (extended) I want to serialize the objects and when i am deserizaling i dont know if i am getting FileMessage or ChatMessage. So how to get that object and use it I have written following code for serialization public void Send(Message message) { NetworkStream netWorkStream=null; try { XmlSerializer serializer=new XmlSerializer(message.GetType()); netWorkStream=new NetworkStream(_clientSocket); Stream stream=(Stream)netWorkStream; serializer.Serialize(stream,message); } finally { netWorkStrea...

XMLSerializer Serialize
Iam trying to create a xml file by serializing a custom business object. Iam using a xmltextwriter, but the problem there are invalid characters at the end of the generated file anyone knows a way around it ? tia Dim myStream As New IO.MemoryStream Dim myXMLWriter As New System.Xml.XmlTextWriter(myStream, System.Text.Encoding.UTF8) myXMLWriter.Formatting = System.Xml.Formatting.Indented Dim myShipments As OrderShipments myShipments = CType(myOrder.OrderAddresses(0), COrderAddress).Shipments myShipments.ToXML(myXMLWriter) ...

Sudden Loss of Direct Statements
My citi credit card statement used to synch just pefectly with money 2003 dx on my Win XP machine. Suddenly, it stopped. I've checked with the bank, and the account was locked because of "too many incorrect login" attempts. After unlocking, I changed the password and tried loging in via the web. That works. Using same information in money yields nothing except lockouts. I've verified the login information several times. It just simply doesn't seem to work from money. (I've got 9 other direct synching accounts from this file that still work just fine...) Anyone ev...

XmlSerializer help
Hi, I have a class: public class Note { public string name; public string information; } And i Serialize this class, but want to Serialize it to an XmlDocument which will contain many of these elements. How do i do this? Thank you, Tim. Timothy, take a look at Chris Lovett's XmlNodeWriter on www.gotdotnet.com [0]. Simply pass the node where you want to insert the serialized XML into the XmlDocument to an XmlNodeWriter and pass the XmlNodeWriter to the Serialize method. -- HTH Christoph Schittko [MVP] Software Architect, .NET Mentor [0] http://gotdotnet.com/Communit...

Problems with XmlSerializer and namespaces
I have an object, Teacher, that has a namespace. Let's call it http://foo. Teacher has a child object called Name, composed of String first, middle, last, etc. Problem I have is when I try to deserialize it. When I deserialize a single Teacher, it works when I put the namespace on the Teacher element. However, if I have just the namespace on Teacher, it will deserialize fine as Teacher. *However*, if I try to deserialize an ArrayOfTeacher, Teacher.Name doesn't deserialize (it's null); without the array, it's OK. What I wound up doing was serializing both a Teacher ...

Direct Printing on Divider Paper
I'm trying to print directly on to the tab. Any ideas? If your printer can handle the larger paper size, then create a document to the width of the paper plus tab and put a borderless text box where the tab should be, put your text in the box and rotate it. I would imagine that it will be quite fiddly to get it right and there's a good change the printer will chew up the tab. That being the case print the tab text on a label and stick it to the tab. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><...

XmlSerializer and ICollection
Hello all, I have two simple classes: Item and ItemCollection. Item stores a label for the item and an instance of ItemCollection for all child items. ItemCollection just stores a collection of Items. ItemCollection implements System.Collections.ICollection. When I use XmlSerializer to serialize an instance of ItemCollection, I am unable to control the element names used to contain the item collection and the items therein. Applying XmlRootAttribute to the ItemCollection class causes an exception because it implements ICollection. I have also tried implementing IXmlSerializer in my ItemColl...

How can OL2000 show picture directly?
Post your questions in the body, not the Subject. By design, Outlook does not display attached images inline. Outlook is a business application. OE is targeted to consumers and the needs of the two groups are different in this area. Exchange Administrators consider inline display a security issue and don't want it. Outlook only shows images inline with HTML mail items or RTF mail items with OLE embedded images. Images in plain text mail items only show as attachments (that you can open or save). -- Russ Valentine [MVP-Outlook] "Litchee" <wonfer@hotmail.com> wrote...

XmlSerializer question
Hi, I use XmlSerializer to serialize xml string. It escapes xml special charaters, like < and > to < and >. How can I stop XmlSerializer to escape these charaters? Thanks in advance!!! Cindy Cindy wrote: > I use XmlSerializer to serialize xml string. It escapes xml special > charaters, like < and > to < and >. How can I stop XmlSerializer to escape > these charaters? If the XmlSerializer didn't escape the characters < and & (and for compatibility >), then the result would not be well-formed XML. See section 2.4 of the XML specification [1]...

how to direct keyboard input to a CWnd added to CDialog?
I have added a CWnd object to a CDialog for the purposes of drawing inside the CDialog. I would like the CWnd object to respond to keyboard input. Any input not handled by CWnd should then be handled by CDialog. Can anyone explain/illustrate how this is done? Thanks for all suggestions and help. Ian ...

VBA code does not work when file open directly in browser
Hi, We are having one Excel file which contain macros. The user has two options to download this report output file, they can download and save to harddisk OR open report into browser directly by using Open command. On the sheet, we gave sort order functionality. The sort order code work correct when user used Download and Save option. However when user used open command to open report directly into browser, report open correct but sort order code not work. The line where i m getting error is given below sSheetName = ActiveSheet.Name Also i m attaching complete code below: Please provide ...

XmlSerializer and DefaultValue?
Hello, I'm currently playing around with the XmlSerializer to replace my old handmade Xml parsing code, but am having a few small issues with default values and derived classes. Say we have classes A, B and C: abstract class A { protected int a_value = 1; [XmlAttribute("value"), DefaultValue(1)] public int AValue { get { return a_value; } set { a_value = value; } } } class B : A { .... } class C : A { .... } Now, I want class B and C to have different default values, more precisely, I want B to have 1 as default value and C to have Int32.MaxValue. But I ...

XmlSerializer question...
Hi All, When using XmlSerializer is there anyway of keeping "xsi", "xsd" namespaces and PI appearing in the xml file ? <?xml version="1.0"?> <myClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="Test" Visible="false" /> Just want a simple clean one like the following... <ColumnInfo Name="Test" Visible="false" /> Thanks, Maersa wrote: > When using XmlSerializer is there anyway of keeping "xsi", "xsd"...

start outlook 2003 directly in my inbox
Have used Outlook Express for years but am being forced to used Outlook 2003. We already have a calendaring system etc. so all we use is the e-mail. I want to open my e-mail and go directly to my inbos. I also do not want to hit send/receive every time I need to check to see if I have a new message - auto delivery is NOT WORKING!!! In news:9CDDEBEA-23E9-4699-985D-B2B5279AD043@microsoft.com, S MCQ <S MCQ@discussions.microsoft.com> typed: > Have used Outlook Express for years but am being forced to used > Outlook 2003. We already have a calendaring system etc. so all we use...

second try
We're using Exchange 2007 Standard Server. Is there anyway to configure a global out of office reply message directly on the Exchange server, so that if message is received on that server it will automatically reply with an "out of office due to inclimate weather message"? We don't want to do it on individual email accounts. We want it to apply to the server. Most of the users have already gone home and do not have the means to put a message on their individual outlook mailboxes. Also, if i am able to only put the message on the server itself, then i'll only...

How to XMLSerialize Collection Class
Hi, I have a collection class where I've implemeneted the ICollection Interface. Here is a small code segment. public class PageList : ICollection, IComparer, IEnumerable, IList { protected ArrayList _pages; public PageList() { _pages = new ArrayList(); } #region IList Members public object this[int index] { get { if (index > _pages.Count) { return (Page)null; } else { return (Page)_pages [index]; } } set { } } public int Add(object objPage) { int arrayIndexAdded = -1; arrayIndexAdded = _pages.A...

Direct Mail
Hi, In the help menu doc, it says the following Recipients of your e-mail will have the option of either requesting more information (thus becoming a lead) or requesting that they be removed from your e-mail list. Is this a built in feature or do i have to do some customisation in other to get this functionality. Has any one got further infomation on this. Kind Regards Abby Hi Abby, please don't double-post. Someone will likely reply to your message within a few days. Thanks, Mike "Abby" <abdul@monere.co.uk> wrote in message news:O2EdaJC4DHA.1592@TK2MSFTNGP10....

Can send and receive e-mail directly, but can't confirm connectivity via telnet to port 25 test method.
Hi all, Pretty new to exchange so I was going through as much documentation as I possibly could to make sure that my first implimentation went as smooth as possible (first setup on a personal server so I can muck it up all I like to make sure that I have it right, no need to subject a client to my expermintation!). I have exchange 2003 enterprise set up on a windows 2003 server standard R2 machine. The machine is the only domain member so it also the AD and DNS primary. Not much else going on with the box other than AD, DNS, and Exchange with little load on any of the three services. It is...