?
Solved

linq to XML doc.save is failing, c#

Posted on 2014-01-24
6
Medium Priority
?
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 63

Expert Comment

by:Fernando Soto
ID: 39825828
Can you post the code that builds the XML document please?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 12

Assisted Solution

by:deanvanrooyen
deanvanrooyen earned 400 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 63

Accepted Solution

by:
Fernando Soto earned 1600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

764 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