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
1960 Views

Similar Articles

[PageSpeed] 7

Reply:

Similar Artilces:

XmlSerializer constructor crashes with 'xsd.exe' generated class
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms to an XML schema (xsd). I've got the schema & I used the xsd utility to create the class (xsd.exe /c properties.xsd /n:somenamespace ). it compiles without a hitch (xsd does a good job of puting '@' around the keyword clashes) When I do XmlSerializer ser = new XmlSerializer(typeof(properties)) I get the standard FileNotFound exception that everyone gets when the DOM compiler fails. The...

using XmlDocument with XHTML
I've really been striking out searching for the answer to this one, so, I'm posting, I really need help :-) I've been attempting to convert client side JavaScript to C Sharp and need to parse XHTML that is really illegal. The browsers can read and parse this terrible example of XHTML I'd like to be able to do it in my code, my attempts have been around using XMLReaderSettings with ignore everything. My end goal is to be able to issue xpath queries against it. So far what I've found in the XML is: no quotes around refresh: <meta http-equiv=refresh cont...

Exchange 2007 Outlook Anywhere connection using TCP/IIP for direct
Exchange 2007 installed on the same AD server . Role in Exchange (Client, Mailbox, UM & Hub) . OWA is working fine. Mail flow is working fine. Outlook configured to connect using Outlook Anywhere , when I check the connection status in outlook Mail type is connecting using HTTPs & all directory type is connecting using TCP/IP Why? What is the fix Thanks Prem ...

XMLDocument.Load() performance
I've got an app that has hundreds of medium-sized (100s of elements) XML files on disk (not in db). Right now these are loaded via XMLDocument.Load and searched with XPATH. The performance has become unacceptable. Performance improvment strategies I know of: 1. Switching to XMLReader 2. general System.XML 2.0 speed improvements 3. SQL Server 2005 : putting the XML in the XML Data Type and : (a) doing XPATH directly against the DB (b) loading the XML from the DB into an XMLDocument and doing XPATH against it Can anyone provide more information? What type of speed improvements can...

XmlSerializer and multi line strings
Hello, can somebody tell me how to serialize/deserialize a object containing a multi line string using the XmlSerializer class. One of the both windows linefeed chars get dumped somewhere down the road. It would be awesome somebody could answer this, sadly most of my questions don't get answered. Regards, Frank "stax" <agfagfagfaf@fdghsgsgs.de> wrote in message news:d60um1$lsj$1@online.de... > One of the both windows linefeed chars get > dumped somewhere down the road. Look at the XML at each point down the road to figure out where the problem lies. > can som...

Direct upgrade from CRM 1.0 to 3.0
Has anybody sucessfully done an upgrade from 1.0 to 3.0 with out first doing an upgrade to 1.2? If so please can you give me some tips how to do this. Thanks You must first upgrade from CRM 1.0 to CRM 1.2 then you can upgrade to CRM 3.0 ======================= John O'Donnell Microsoft CRM MVP http://codegallery.gotdotnet.com/crm "John Steskal" <John Steskal@discussions.microsoft.com> wrote in message news:1F5178F3-84CF-4A44-8D9A-7668BAA3CEFA@microsoft.com... > Has anybody sucessfully done an upgrade from 1.0 to 3.0 with out first > doing an upgrade to 1.2? If...

How to print Directly from Dialog based application
HI all, I am writing MFC Extension DLl which has dialog in it. It has list of documents ( like .doc,.xls,.pdf etc....) When user double clicks the document I do ShellExecute to open it..... Now i have print button . When user clicks Print button Selected document in the list should be printed...... I want to print that document directly ( that is without opening corresponding application....e.g. want to print 1.doc without opening MSWord) How can i achive this? Will DDE command will help ? How? Any Guidence Or Link for that? I have tried with ShellexecuteEx with "print" as verb ...

PLEASE explain xmlDocument on server, but the html transform on client???
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the html transform but inside the aspx page, could I change and save the xmlDoc that way? Sorry to be so dense about this...PLEASE help me out with explanation...

Newbie needs a direction
Jeff Boyce bravely tried to help me: http://groups.google.com/group/microsoft.public.access/browse_thread/thread/35bf6e83d16813ec?hl=en and I greatly appreciate all his effort. Unfortunately, Jeff or anyone else, I think I don't know enough about what I am wanting to do to get there from what I have been given so far. Here's the basics of what I want to accomplish: Think of something like an auto repair shop. For each invoice, you have info about one car, with many lines of work time and many lines of parts replaced. I want to wind up with a report that shows for each invoice numbe...

Direct Marketing
I just purchased Microsoft Publisher 2007. I have a designed marketing letter that I would like to import into Publisher and create new fields to import my customers name, address, and other info. that save in excel. Is this software capable of uploading my letter and creating new fields to import the necessary customer data???? I'm looking to print out 5,000 letter with the 5,000 different name and address information listed on my designed letter. Is this possible with this software??? BNB 1ST CAPITOL wrote: > Is this possible with this software??? Yes. Look up Mail...

Money 2006 and ING Direct
I cannot download information through Money 2006 from ING Direct. I fill out all the information that is required, but it does not work? Anyone know why? How are you trying to do this? Set up for automatic downloads. Manually with Money open? Manually to an ofx file? -- Peace, BobJ "cjsherlock" <cjsherlock@discussions.microsoft.com> wrote in message news:2E16B72C-CAFA-4A3B-A928-52C64F6FCCA5@microsoft.com... >I cannot download information through Money 2006 from ING Direct. I fill >out > all the information that is required, but it does not work? Anyone know ...

Archiving PSTs directly from a server
Greetings: I work for a government archive and have been tasked with completing a preservation project - we have received an Exchange server (WIndows 2000/SP 4 and Exchange 2000) to which I have full admin rights. [Usually entities that are sending us records do the exporting themselves but not in this case, so they handed us the entire server instead.] I know enough about Exchange to hopefully get through this since we don't have to make any changes or actually administer this as a working server - just get the email off the server and preserve it (for now) on archival-quality media. ...

text direction
I want to rotate my text in in a Word document, but my TEXT DIRECTION command is gray and not accessable. What can I do? Thank you. Ask in a Word newsgroup? -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "djdon" <djdon@discussions.microsoft.com> wrote in message news:92764CFC-2474-44EA-ADB0-8D5C3F922769@microsoft.com... >I want to rotate my text in in a Word document, but my TEXT DIRECTION command > is gray and not accessable. What can I do? Thank you. "djdon" <djdon@discussions.microsoft.com&...

Why does calendar dates that I receive go directly to "Delete" box
Calendar dates that I receive from others in the bldg. go directly to my "Delete" box. Does anyone know how I can change them to go to my "Inbox"? Are the appointments added to your calendar? What is your configuration in Tools, options, email options, tracking options: http://slipstick.me/jing/receipts.png -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newslette...

XMLDocument serilization date format
Hiyas, Using VS .net 2003. Setting up a Webservice that accepts 3rd party vendor designed XML requests and returns a filled XMLDocument with response data. Vendor XSDs were serialize into class objects to be used in the program. EX: Used xsd.exe to turn VendorA_Request.XSD into VendorA_Request.cs EX: Used xsd.exe to turn VendorA_Response.XSD into VendorA_Response.cs etc etc.. Program logic is like this: Webservice accepts an XML request as a string. Deserialize the string into its appropriate request class object. Run the request class through business logic and produce result class. Ser...

mailing directly from publisher people reciveing see it incorrectl
I am trying to mail people directly from my publisher program, I select send e.mail as attachment and when people recive this message it looks like it has 1 / 2 or even 3 parts to it and that they have not been put back together properly, the effect looks something like wallpaper and the pattern doesn't match - this makes for almost impossible reading - has any one else suffered this problem? Any ideas for a souloution Thanks iamsquid <iamsquid@discussions.microsoft.com> was very recently heard to utter: > I am trying to mail people directly from my publisher program, I &g...

Cannot send direct emails
i was unable to send direct emails through the CRM, i ran a repair and found several errors so i installed everything from scratch on a clean system. Still i cannot send direct emails from My Workplace in CRM. But i can send emails through the outlook on the client pc. I have seen that most of the issues submitted here in the community, refer to the inability of sending emails. therefore, i would like to speak with someone who has his CRM up and working, as i have spent almost a week trying to figure out what's going on. i have also purchased MailMerge for including attachments in ...

I direct access 2003 to sku111.cab i get error 25091
when trying to load subform/subreport in access 2003 message saids can't find sku111.cab, I insert office pro 2003 then click message to install from office cd. It then saids cant find it. I then try again using browse, and direct access to its exact position it then saids error 25091... I have copied sku111.cab to desktop from office pro 2003. I then re-directed access to find it on my desktop...same error message .. sku111 is in a winwar file I could unzip it, but not sure where to place contents.. its driving me insane.. any help would appreciated... thanks..... ...

Limit Direct Deposit Transaction Register to the current build
The DD Transaction Register will include all transactions for all builds currently in the Generate ACH window. If the client has prior builds in the Generate ACH window these transactions will also be listed on the report. They will see a break between each pay run (Name = Payroll), which will list the total for each pay run. We would like to suggest that this report only print the build the user marked in the Generate ACH window. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click...

Can't understand directions to change hotmail to new pop3 imap, etc
Help. How do I make this transition? Windows Mail doesn't support HTTP mail, which for a long time was the=20 only allowed access method for free Hotmail accounts. Last February, Microsoft enabled POP access (not IMAP) for free=20 Hotmail/Live/MSN accounts. Follow the settings given here: http://mailcall.spaces.live.com/Blog/cns!CC9301187A51FE33!49799.entry Use port 587 rather than port 25 for the SMTP server. Although it accepts the newer Live.com addresses, Windows Mail's=20 account setup wizard is hard-coded to reject Hotmail and MSN addresses. To get around that, when...

XMLSerializer problem, class inside class
Hi, I'm having a problem with XMLSerializer, I have classes like the following: [Serializable] public abstract class EulerObject { private Rectangle rect; private string guid = ""; public virtual Rectangle Rect { get { return rect; } set{ rect = value; } } public string GUID { get { return guid; } set { guid = value; } } public abstract void Draw(Graphics g); public abstract EulerObject MakeCopy(bool sameGuid); } [Serializable]...

XmlSerializer would not serialize properties in the class derived from List<T>
I have following 3 classes public class MyMainClass { MyCollection<MyObject> m_oMyObjectCollection = null; private string m_sID = string.Empty; public MyCollection<MyObject> Collection { get { return this.m_oMyObjectCollection; } set { this.m_oMyObjectCollection = value; } } [XmlAttribute] public string ID { get { return this.m_sID; } set ...

file emails direct from pressing the SEND button?
I want to file me emails when i press the SEND button. Is this possible? rosail <rosail@discussions.microsoft.com> wrote: > I want to file me emails when i press the SEND button. Is this > possible? File them how? Have you used Help and looked at "create a rule" yet? -- Brian Tillman [MVP-Outlook] ...

RTF my default; button to create HTML message directly?
My mail message format default is RTF, which is what I need. But every once in a while, I like to write a msg in HTML to friends and family because I'll send embedded graphics. I'm tired of having clicking new message, then on the option to change to text format and then to change to html. Is there a more direct route to pull up an html new msg without going, say, the blank stationery msg route? That's all that occurs to me to do, but it's a drag as I'd have to remember to carry around a blank html msg to each new contract and dump it in the stationery fldr on to...

Treasury Direct email and replies
Did any other acount holders get an email from Treasury Direct asking to update your email and home addresses and phone number, and then get a bunch of replies to that email from other recipients? Someone at Treasury Direct claimed it was a server error. Still wondering why "Jane Doe's", "John Smith's" and "Barney Fife's" response to that email was sent to me. Lena The new Treasury Direct? Or the Legacy one? -- Michael Gordon MVP "Lena" <lenagainster@gmail.com> wrote in message news:1158608262.972775.214990@k70g2000cwa.googleg...