【发布时间】:2014-12-06 09:56:53
【问题描述】:
IDE:VS、C# .net 4.0、winforms
在 XMLSerializer 的帮助下,我能够生成 C# 对象的 XML,但我想删除特定对象。
有什么方法可以防止特定对象在 XML 中被阻止..?
using (MemoryStream xmlStream = new MemoryStream())
{
/*
XmlSerializer.Serialize Method (XmlWriter, Object)
Serializes the specified Object and writes the XML document to a file using the specified xmlwriter
Parameters
xmlWriter-
Type: System.Xml.XmlWriter
The XmlWriter used to write the XML document.
Type: System.Object
The Object to serialize.
*/
xmlSerializer.Serialize(xmlStream, YourClassObject);
xmlStream.Position = 0;
//Loads the XML document from the specified string.
xmlDoc.Load(xmlStream);
string fileName = YourClassObject.GetType().Name;
xmlDoc.Save("C:\\Users\\Yogesh\\Desktop\\Yardz_XMLS\\" + fileName + ".xml");
return xmlDoc.InnerXml;
有什么方法可以防止某些属性被序列化..?
【问题讨论】:
-
防止序列化特定的对象或属性?后者很容易。另一方面,前者取决于你的真正意思。