转换的XElement字符串 [英] Convert XElement to string

查看:786
本文介绍了转换的XElement字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的XElement对象

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")
);



如果想要的内容转储到一个字符串。究竟怎么样 Console.Writeline(XML); 做,但我想在一个字符串的内容。我尝试过各种methonds。 xml.ToString(); 不返回自身的东西。

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

推荐答案

的ToString应该肯定大部分工作。我用它所有的时间。是什么在这种情况下,返回给你?空字符串?我的猜测是出事了构建的XElement。为了调试,重写代码添加每个孩子XElements分开,这样就可以逐步代码并检查他们每个人。你执行的ToString在此之前,在本地窗口,看看扩展到XML中的[XML]变量。

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.

总之,你有机会在你的问题发生以ToString()方法。

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

这篇关于转换的XElement字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆