Tag: xml serialization

使用.NET XML序列化在其他元素中包装序列化属性

我使用C#+ VSTS2008 + .Net 3.0来进行XML序列化。 代码工作正常。 下面是我的代码和当前序列化的XML结果。 现在我想在输出XML文件中添加两个附加层。 这是我期望的XML结果。 有什么简单的方法吗? 我不确定NestingLevel是否可以帮助这样做。 我想找到一种不会改变MyClass和MyObject结构的简单方法。 预期的XML序列化结果, Foo 当前的XML序列化结果, Foo 我目前的代码, public class MyClass { public MyObject MyObjectProperty; } public class MyObject { public string ObjectName; } public class Program { static void Main(string[] args) { XmlSerializer s = new XmlSerializer(typeof(MyClass)); FileStream fs = new FileStream(“foo.xml”, FileMode.Create); MyClass instance […]

WCF中IsWrapped属性的用途是什么

WCF中“IsWrapped”属性的用途是什么。 我应该在哪种情况下使用这个属性?为什么?

如何从xml字典序列化中正确删除xmln:xsi和xmlns:xsd

问题:我使用的是可序列化的字典类 http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx ,序列化字典。 它适用于下面的示例类。 _ Public Class ccl _ Public xx As String = “” _ Public yy As String = “” ‘ _ ‘Public ww As New SerializableDictionary(Of String, String) End Class 但它增加了一个, xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance AND xmlns:xsd=”http://www.w3.org/2001/XMLSchema? 到标签 现在我通过将字典类更改为来修复它 Dim ns As System.Xml.Serialization.XmlSerializerNamespaces = New System.Xml.Serialization.XmlSerializerNamespaces() ‘Add an empty namespace and empty value ns.Add(“”, “”) […]

在C#中将XML反序列化为类obj

这是我在200多个这样的条目的巨大XML文件中的条目之一。 xxx xxxxxxxxxxxxxxxxxxx xxx xxxxxxxxxxxxxxxxx xxxxxxxx x xxxxxxxxxxxxxxxx xx xxxxx xxxxxxxx xxxxxxx xxxx xxxxxxxx xx xxxx xxx xxxx x xx xxxxx xxxxxxxxxxxxxxx xxxxxxxxxxx 我试图将其反序列化为类对象,但每次都失败。 到目前为止这是我的代码: using System; 使用System.Collections.Generic; 使用System.Text; 使用System.IO; 使用System.Xml.Serialization; namespace DeserializeXML {public class Program { // This is the class that will be deserialized. [Serializable()] public class TradeFill { [XmlElement(“Broker”)] public string broker; […]

Serialize()不使用Sgen生成的.XmlSerializers.dll

我的.NET 3.5库中有一个sgen步骤,在输出目录中生成一个正确的XYZ.XmlSerializers.dll。 仍然有较差的序列化性能,我发现.NET仍然在运行时调用csc。 使用进程监视器,我看到.NET正在搜索名为“XYZ.XmlSerializers.-1378521009.dll”的DLL。 为什么文件名中有’-1378521009’? 如何告诉.NET使用sgen生成的“普通”DLL?

为什么这个类属性没有序列化?

[Serializable] public class ProfilesCollection : ObservableCollection { public ProfilesCollection() { } } [Serializable] public class Profile : ObservableCollection { private string _name; public string Name { get { return _name; } set { _name = value; OnPropertyChanged(new PropertyChangedEventArgs(“Name”)); } } public Profile() { } } [Serializable] public class SomeData : INotifyPropertyChanged { // some properties […]

从类生成XML

我想从一个类构建以下XML节点。 some value 我的class级定义应该如何? class Foo { public string Value {set;get;} public string id{set;get;} } 我相信我应该为这些属性添加一些XML属性,但不确定它们是什么。

使用XmlSerializer进行自定义序列化

我有一个类,我需要从中做一些自定义XML输出,因此我实现了IXmlSerializable接口。 但是,我希望使用默认序列化输出的某些字段,但我想更改xml标记名称。 当我调用serializer.Serialize时,我在XML中获得默认标记名称。 我能以某种方式改变这些吗? 这是我的代码: public class myClass: IXmlSerializable { //Some fields here that I do the custom serializing on … // These fields I want the default serialization on except for tag names public string[] BatchId { get; set; } … … ReadXml and GetSchema methods are here … public void WriteXml(XmlWriter writer) { […]

部分xml序列化/反序列化

是否可以从/串行部分(de)/序列化对象? class Foo { Bar Bar{get;set;} string XmlJunkAsString{get;set;} } 如此超级,我们希望下面的字符串能够工作…… 最终我们可以找到Foo.XmlJunkAsString的内容来包含字符串 反之亦然,当序列化这个特定的Foo实例时,会产生上面的xml。 可能?

使用XPath实现IXmlSerializable ReadXml()的最佳方法

我正在实现IXmlSerializable的ReadXml()方法,我认为使用XPath可能是最好的方法。 但是,ReadXml()需要正确处理读者位置。 因为我的WriteXml()产生了这样的东西: 2 2 是否有比下面(这种可怕的方式)更好的方法来确保读者之后的正确定位? public override void ReadXml(System.Xml.XmlReader reader) { reader.Read(); /* Read Opening tag */ /* Using reader.ReadStartElement(“ObjectName”) reads forward a node, ie current node becomes the first whereas Read() doesn’t even when the documentation says they both do */ XPathNavigator n = MakeXPathNavigator(reader.ReadSubtree()); XPathNodeIterator nodes = n.Select(“.//SubNode”); while (nodes.MoveNext()) { /* […]