Tag: xml serialization

XML序列化结构

抱歉不能更具体地说出标题,但我只能举一个例子来解释。 我正在尝试构建一个序列化为以下XML的类 我的C#是: [XmlRoot] public Customize Customize { get; set; } 和 public class Customize { public List Content { get; set; } public List Command { get; set; } } 但是,这会产生(应该如此),以下内容: 是否有一些xml序列化属性可以帮助实现我想要的xml,或者我是否必须找到另一种编写类的方法?

使用xml属性创建XML结构

我正在尝试用xml属性解决一个难题。 问题是我们已经广泛使用了具有这种结构的文件,我不能偏离它 c1 v1 v2 v3 c2 v1 v2 v3 我已经创建了这个c#代码 // master class [XmlRoot(ElementName = “CONFIGS”)] public class MyConfigs { [XmlArrayItem(ElementName = “CONFIG”, Type = typeof(MyConfigSchema))] public MyConfigSchema[] Schemas { get; set; } } // I should have array of these public class MyConfigSchema { [XmlElement(DataType = “string”, ElementName = “NAME”)] public string Name […]

C#使用Visual Studio生成的类从xml节点获取所有文本,包括xml标记

在visual studio中使用xml到c#function将下面的xml标记转换为C#类。 Author-11 Author-11 转换后的类包含 [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] public partial class booksBookAuthorName { private byte refField; // 1 private string[] textField; // 2 我们需要的是Author-11作为输出,通过保持读取作者姓名 标签。 我们尝试过https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmltextattribute(v=vs.110).aspx属性。 但没有希望。 任何线索?

将空XML元素渲染为父元素

我有一个奇怪的要求,即我的应用程序生成的消耗一些XML的应用程序实际上需要将空元素序列化为父元素。 例如: 应该: 我不知道XmlSerializer允许你改变它的任何方式。 有谁知道如何做到这一点?

Web服务 – 派生类中的XmlInclude而不是基类?

我使用抽象类作为Web服务调用中的参数。 目前,我在基类中包含了一个派生类的XmlInclude,如下所示: [XmlInclude(typeof(DerivedClass))] public abstract class BaseClass { } 但是,我宁愿不在基类中包含所有派生类型。 在http://www.pluralsight.com/community/blogs/craig/archive/2004/07/08/1580.aspx中 ,作者提到了另一种选择 – 将属性写在Web方法之上,如下所示: [WebMethod] [System.Xml.Serialization.XmlInclude(typeof(DerivedClass))] public BaseClass getClass() { return new DerivedClass(); } 但是,我也不想将派生类型放在Web服务中。 有没有办法将属性保留在派生类型中?

不完整的XML属性

我是通过dataset.GetXML()方法从Dataset创建XML。 我想为它添加属性 XmlAttribute attr = xmlObj.CreateAttribute(“xmlns:xsi”); attr.Value = “http://www.createattribute.com”; xmlObj.DocumentElement.Attributes.Append(attr); attr = xmlObj.CreateAttribute(“xsi:schemaLocation”); attr.Value = “http://www.createattribute.com/schema.xsd”; xmlObj.DocumentElement.Attributes.Append(attr); xmlObj.DocumentElement.Attributes.Append(attr); 但是当我打开XML文件时,我发现schemaLocation的属性中没有“xsi:” 我想要这个属性 xsi:schemaLocation=”http://www.createattribute.com/schema.xsd” 这总是这样,或者我在这里遗漏了一些东西。 我很好奇是否有人可以帮助我,如果这可以解决或给我一些URL,我可以找到解决方案 谢谢

使用

我正在尝试保留对象的两个不同版本的数据,并且没有取得任何成功。 谁能告诉我我做错了什么? 版本之一: [DataContract (Name=”Person”)] public class Person_V1 { [DataMember(Name = “Name”)] public string Name; [DataMember(Name = “Age”)] public int Age; [XmlAnyElement] public XmlElement[] XElements; } 第二版: [DataContract(Name = “Person”)] public class Person_V2 { [DataMember(Name = “Name”)] public string Name; [DataMember(Name = “Age”)] public int Age; [DataMember(Name = “Weight”)] public int Weight; [XmlAnyElement] public XmlElement[] […]

如何定义XmlSerializer使用的文化

我使用以下代码反序列化xml配置文件: // Create object by deserializing the given xml document var serializer = new XmlSerializer(typeof(ConfigurationFile)); var stream = File.Open(path, FileMode.Open, FileAccess.Read); var configFile = serializer.Deserialize(stream); 在配置中,我有一些浮动数字定义如下: DailyThreshold = “41.9” 作为小数分隔符“。” 是文化依赖我想知道我如何定义序列化程序用来解析这些数字的文化?

如何从对象列表创建xml文件

我定义了3个类: public class PublishedPage { public string Action { get; private set; } public string PageGuid { get; set; } public List SearchableProperties { get; set; } public PublishedPage() { Action = “Published”; SearchableProperties = new List(); } } public class DeletedPage { public string Action { get; private set; } public string PageGuid { […]

.net XmlSerializer,忽略基类属性

假设我们从基类“System.Windows.Controls”中有一个派生类“SerializableLabel”。 [XmlRoot(“SerializableLabel”)] public class SerializableLabel : Label { public string foo = “bar”; } 我想序列化这个类,但忽略父类中的所有属性。 理想情况下,xml看起来像: bar 如何最好地实现这一目标? 我的第一次尝试使用了典型的XmlSerializer方法: XmlSerializer s = new XmlSerializer(typeof(SerializableLabel)); TextWriter w = new StreamWriter(“test.xml”); s.Serialize(w, lbl); w.Close(); 但是这会引发exception,因为序列化程序会尝试序列化一个基类属性,这是一个接口(ICommand Command)。