Solved

linq to XML doc.save is failing, c#

Posted on 2014-01-24
6
285 Views
Last Modified: 2016-02-10
I have a c# program that creates an xml document using linq to xml:

XDocment doc = new XDocument();

there are over 600 lines of logic building this xml file, culminating in:

string fName = this._writepath + "file856" + curDateTime + ".xml";
doc.Save(fName);


at doc.Save I am getting an error:  This operation would create an incorrectly strucutred document.  

Unfortunately, this error doesn't happen in my development environment, only in the delivery environment (the executable on the client's machine).

Is there anything I can do to get the executable to show me the structure of the xml so that I can see where it's malformed?  In other words, since doc.Save fails, is there some way to throw it into a viewer or a NotePad or something else that would allow me to look at it?
0
Comment
Question by:g_johnson
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 39808032
does this help?

http://stackoverflow.com/questions/4533609/how-to-get-xml-as-string-from-xdocument

what encoding are you using, be very wary of UT8 or other non standard formats
0
 
LVL 4

Author Comment

by:g_johnson
ID: 39824314
I'm using utf-8.  How does that play into this?  The .ToString() method returned the same error.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39825828
Can you post the code that builds the XML document please?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Assisted Solution

by:deanvanrooyen
deanvanrooyen earned 100 total points
ID: 39827091
typo - should have been utf-8, utf-8 generally should be ok then - you probably constructing a document that is not well formed...
0
 
LVL 4

Author Comment

by:g_johnson
ID: 39840128
Correct -- I agree that it's not well-formed.  I am looking for a way to display it so that I can spot the error.  So far, I have not been able to get any application of .ToString() to do that for me.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 400 total points
ID: 39840158
The problem is that when you create the document it goes through a XML validation process and if it fails it will not get loaded and therefore there will nothing to print. To find the issue you will need to go through the code that creates it and find where it is being malformed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why, and when, to use Windows Workflow 1 31
Performance  Html.BeginForm vs jQuery 3 45
Vb.net dynamic formulas in runtime 11 61
Export import database 4 40
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now