xml-serialization

Remove “d1p1” namespace prefix in DataContractSerializer XML output

一曲冷凌霜 提交于 2019-12-21 07:34:32
问题 I'm using DatacontractSerializer to serialize my domainModel into a xml file. I'm getting output like below. <z:anyType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:d1p1="DCSerialization_IGITApproach" i:type="d1p1:X" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> <d1p1:Name z:Id="2">Ankit</d1p1:Name> <d1p1:PointsDictionary xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" z:Id="3" z:Size="1"> <d2p1:KeyValueOfstringPointsArrayq9VX7VJJ>

XmlSerializer and List<T> with default values

[亡魂溺海] 提交于 2019-12-21 07:30:31
问题 I observed a weird behavior when serializing and than deserializing a class that is having a member of type List<T> which was filled with default values at construction time. Unlike the array based property the property of type List<T> won't get emptied at deserialization by the XmlSerializer. Here is my code: public class Program { public class Config { public Config() { Test1 = new List<string>() {"A", "B"}; Test2 = new String[] {"A", "B"}; } public List<string> Test1 {get;set;} public

XML to/from a Python dictionary

浪尽此生 提交于 2019-12-21 05:39:16
问题 I need to use Python 2.4.4 to convert XML to and from a Python dictionary. All I need are the node names and values, I'm not worried about attributes because the XML I'm parsing doesn't have any. I can't use ElementTree because that isn't available for 2.4.4, and I can't use 3rd party libraries due to my work environment. What's the easiest way for me to do this? Are there any good snippets? Also, if there isn't an easy way to do this, are there any alternative serialization formats that

Jibx - how to unmarshal/marshal tag with value and attribute?

假如想象 提交于 2019-12-21 05:22:26
问题 <stateData> <MyTag name="voltage">12</Mytag> <MyTag name="Fuel">72</Mytag> </stateData> Sorry Guys, I did not meant to be lazy. Ok Here is the question: I have xml structure with above block of xml which some tags has both value and attribute in tag notation( MyTag has value of 12 and has an attribute name). using Jibx how I can create binding schema for such case. Obviously for xml tags with only value or with attributes without tag value is normal, but when you have both of them I don't

XML serialization errors when trying to serialize Entity Framework objects

梦想与她 提交于 2019-12-21 05:08:12
问题 I have entities that I am getting via Entity Framework. I'm using Code-First so they're POCOs. When I try to XML Serialize them using XmlSerializer, I get the following error: The type System.Data.Entity.DynamicProxies.Song_C59F4614EED1B7373D79AAB4E7263036C9CF6543274A9D62A9D8494FB01F2127 was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. Anybody got any ideas on how to get around this (short of creating a whole new object)? 回答1: Just

Why does MSBuild put *.XmlSerializers.dll assembly in the root folder of published web application?

£可爱£侵袭症+ 提交于 2019-12-21 04:26:07
问题 I have a build process which takes my VS 2008 .NET 2.0 ASP.NET project and builds it using MSBuild. The project contains ASPX files, plus a web service, and also connects to another web service ;) All seems to work well except MSBuild puts the *.XmlSerializers.dll assembly file into the folder _PublishedWebsites\MySite rather than in _PublishedWebsites\MySite\bin like it does with the other dll. Does it matter that the *.XmlSerializers.dll assembly file is not in the bin folder? Or should I

How do Inheritance and JAXB work together?

半城伤御伤魂 提交于 2019-12-21 03:36:21
问题 public abstract class Parent<T> { protected List<T> list; @XmlTransient //Question why do we have to give this here? public abstract List<T> getList(); public abstract void setList(List<T> list); } @XmlRootElement(name = "child1") class Child1 extends Parent<ExtendedElement1>{ @Override public void setList(List<ExtendedElement1> list){ this.list = list; } @Override @XmlElementWrapper(name = "child1-list") @XmlElement(name = "child-list-element") public List<ExtendedElement1> getList(){ return

XML Serialization in C#

大兔子大兔子 提交于 2019-12-20 20:31:15
问题 Where Can I find good tutorial about XMl serialization to the object? Thanks. 回答1: There's a basic tutorial on Microsoft's support pages and their code example is only a few lines long: using System; public class clsPerson { public string FirstName; public string MI; public string LastName; } class class1 { static void Main(string[] args) { clsPerson p=new clsPerson(); p.FirstName = "Jeff"; p.MI = "A"; p.LastName = "Price"; System.Xml.Serialization.XmlSerializer x = new System.Xml

XmlSerializer exception when deserializing derived class (<Derived xmlns=''> was not expected)

眉间皱痕 提交于 2019-12-20 07:14:15
问题 I am trying to serialize and deserialize a hierarchy of classes using XmlSerializer. The serialization works fine, but when I try to deserialize I get this exception: System.InvalidOperationException: There is an error in XML document (2, 2). ---> System.InvalidOperationException: <Derived xmlns=''> was not expected. This is the xml that I am trying to deserialize: <?xml version="1.0"?> <Derived xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"

Render Empty XML Elements as Parent Elements

限于喜欢 提交于 2019-12-20 04:34:51
问题 I have a strange requirement where an application consuming some XML that my application is generating actually needs empty elements to be serialized as parent elements. For example: <element foo="bar" /> should be: <element foo="bar"></element> I'm not aware of any way that the XmlSerializer allows you to change this. Does anybody know how to accomplish this? 回答1: I extended XmlTextWriter so that I could override the WriteEndElement() method, forcing it to call WriteFullEndElement(). This