views:

1086

answers:

1

Hi all,

I have a simple XElement object

 XElement xml = new XElement("XML",
                            new XElement ("TOKEN",Session["Token"]),
                            new XElement("ALL_INCLUSIVE", "0"),
                            new XElement("BEACH", "0"),
                            new XElement("DEST_DEP", ddlDest.SelectedValue.ToString()),
                            new XElement("FLEX", "0")
                );

Where want to dump out the contents into a string. Exactly like how Console.Writeline(xml); does, but I want the contents in a string. I tried various methonds. xml.ToString(); doesn't return anything on its own.

Thanks a lot, Marty

+5  A: 

ToString should most definately work. I use it all the time. What does it return for you in this case? An empty string? My guess is that something went wrong building your XElement. To debug, rewrite the code to add each of the child XElements separately, so that you can step through your code and check on each of them. Then before you execute the .ToString, in the Locals window, look at the [xml] variable expanded to xml.

In short, your problem is happening before you ever get to the ToString() method.

Patrick Karcher
yeah just an empty string. But I'm sure that there's data in xml since Console.Writeline(xml) returns something. I know I'm missing something obvious.
omgitsmarty
Yeah Just found it. It was real silly. This is a Web App and I was sending the results to the browser with other HTML so it wasn't rendered but the xml did exist in the page when I viewed source. I think that's my hint to stop working today. Thanks!
omgitsmarty
We please to aim!
Patrick Karcher