如何将类实体转换为xml [英] how to convert class entities in to xml

查看:420
本文介绍了如何将类实体转换为xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







i必须这样转换



class test = new class();



test.name =raju;



兑换这个in to xml



测试为root标签和



名称作为子标签









感谢adv,



Ragards,

Rahul。

Hi,


i have to convert like this

class test=new class();

test.name="raju";

convert this in to xml

test as root tag and

name as sub tag




Thanks in adv,

Ragards,
Rahul.

推荐答案

请参阅以下链接,已经讨论过一个很好的例子



序列化列表 - 列表到-xml
See the following link which is already discussed with a good example

serializing-lists-of-classes-to-xml


你可以尝试这个...



You may try this...

public string EntityToXML()
    {
        var stringwriter = new System.IO.StringWriter();
        var serializer = new XmlSerializer(this.GetType());
        serializer.Serialize(stringwriter, this);
        return stringwriter.ToString();
    }


您可以参考下面的链接来帮助您



< a href =http://tech.pro/tutorial/798/csharp-tutorial-xml-serialization> http://tech.pro/tutorial/798/csharp-tutorial-xml-serialization [< a href =http://tech.pro/tutorial/798/csharp-tutorial-xml-serializationtarget =_ blanktitle =新窗口> ^ ]
You can refer the below link which will help you

http://tech.pro/tutorial/798/csharp-tutorial-xml-serialization[^]


这篇关于如何将类实体转换为xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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