Link to home
Start Free TrialLog in
Avatar of g_johnson
g_johnsonFlag for United States of America

asked on

linq to XML doc.save is failing, c#

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?
Avatar of deanvanrooyen
deanvanrooyen

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
Avatar of g_johnson

ASKER

I'm using utf-8.  How does that play into this?  The .ToString() method returned the same error.
Avatar of Fernando Soto
Can you post the code that builds the XML document please?
SOLUTION
Avatar of deanvanrooyen
deanvanrooyen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial