[英]create xml from webform in asp.net mvc 2 c#
what is the easiest way to create a structured xml file based on asp.net mvc 2 webform data ? 基于asp.net mvc 2 Webform数据创建结构化xml文件的最简单方法是什么? i am looking for ac# solution and to use maybe linq/lambda expressions? 我正在寻找ac#解决方案,并可能使用linq / lambda表达式?
You can deserialize your model to Xml in your controller method ActionResult SaveMyObject(MySerializableClass myObject){ //do stuff here }
您可以在控制器方法ActionResult SaveMyObject(MySerializableClass myObject){ //do stuff here }
模型反序列化为Xml
You should be able to use one of the overloaded XmlSerializer.Deserialize
methods found within the System.Xml.Serialization
namespace. 您应该能够使用System.Xml.Serialization
命名空间中的重载XmlSerializer.Deserialize
方法之一。
This is one example, found on the MSDN Documentation site 这是一个示例,可以在MSDN文档站点上找到
MySerializableClass myObject;
// Construct an instance of the XmlSerializer with the type
// of object that is being deserialized.
XmlSerializer mySerializer = new XmlSerializer(typeof(MySerializableClass));
// To read the file, create a FileStream.
FileStream myFileStream = new FileStream("myFileName.xml", FileMode.Open);
// Call the Deserialize method and cast to the object type.
myObject = (MySerializableClass)
mySerializer.Deserialize(myFileStream)
Your object will then be deserialized into the file. 然后,您的对象将反序列化到文件中。 You could also use the MemoryStream
class to deserialize it into a string variable 您还可以使用MemoryStream
类将其反序列化为字符串变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.