xmlserializer

XmlSerializer List Item Element Name

时间秒杀一切 提交于 2019-12-28 05:36:27
问题 I have a class PersonList [XmlRoot("Persons")] PersonList : List<Human> when I serialize this to XML, by default it will produce something like this: <Persons> <Human>...</Human> <Human>...</Human> </Persons> My question is what needs to be done in order to change element Human to Person in the output? so the output would be : <Persons> <Person>...</Person> <Person>...</Person> </Persons> and, how to deserialize the above XML to the PersonList class object? Per Nick's advice, Here is my

How to write a comment to an XML file when using the XmlSerializer?

大兔子大兔子 提交于 2019-12-28 02:44:29
问题 I have an object Foo which I serialize to an XML stream. public class Foo { // The application version, NOT the file version! public string Version {get;set;} public string Name {get;set;} } Foo foo = new Foo { Version = "1.0", Name = "Bar" }; XmlSerializer xmlSerializer = new XmlSerializer(foo.GetType()); This works fast, easy and does everything currently required. The problem I'm having is that I need to maintain a separate documentation file with some minor remarks. As in the above

How to deserialize XML attribute of type long to UTC DateTime?

*爱你&永不变心* 提交于 2019-12-25 07:59:18
问题 Following these answers, I've decided to use xsd.exe and XmlSerializer as the most simple way to parse XML. But I want some refinements: My top request is changing MyRoot.Time type from long to DateTime . It can be achieve easily by code using DateTime.FromFileTimeUtc or new DateTime, but can it be done directly by the XmlSerializer? Can I change MyRoot.Children type into something more complex like Dictionary<string,Tuple<int,ChildState>> ? My XML: <Root timeUTC="129428675154617102"> <Child

XmlSerializer Won't Deserialize over NetworkStream

蓝咒 提交于 2019-12-25 01:47:01
问题 I'm looking to implement a simple Client/Server setup that can transfer a serialized EmailRequest object (using XmlSerializer ) from the client to the server, to be used to send an email. Server class Program { private static void Main() { try { TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8888); listener.Start(); while (true) { Console.WriteLine("Waiting for request.."); TcpClient client = listener.AcceptTcpClient(); NetworkStream stream = client.GetStream();

XmlSerializer attribute namespace for element type dt:dt namespace

前提是你 提交于 2019-12-24 16:26:07
问题 I'm looking for the XmlSerializer functionality to re-create some namespace/type info in my output XML. So I have to replicate XML output like this to an old COM application: <Amount dt:dt="int">500</Amount> <StartTime dt:dt="dateTime">2014-12-30T12:00:00.000</StartTime> I currently set the attributes of my properties like so: [XmlElement(ElementName = "Amount", Namespace = "urn:schemas-microsoft-com:datatypes", DataType = "int", Type = typeof(int))] public int Amount{ get; set; } With my

Adding the Parent id to Serialization as Object class

北慕城南 提交于 2019-12-24 15:39:30
问题 I have the following XML file which I am using the VSC#(windows forms) code to save it as a class: <Steps > <Step id ="1" Name="S1"> <Step id ="2" Name="S11"> <Step id ="3" Name="S111" /> <Step id ="4" Name="S112" /> <Step id ="5" Name="S1121" /> </Step > <Step id ="6" Name="S12" /> </Step > </Steps > The code I wrote as: [System.SerializableAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] [System.Xml

Serialize part of xml file. Want namespace on root, not on serialized subelements

Deadly 提交于 2019-12-24 12:51:33
问题 I'm trying to make an Xml file that looks something like: <RootLevel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.MyCompany.com/MySchema.xsd"> <Level1> <Level2> </Level2> </Level1 > <Level1> <Level2> </Level2> </Level1 > etc. repeats hundreds of times </RootLevel> I generated some classes from my xml schema definition file using the xsd.exe utility. They look like: [System.Xml.Serialization.XmlTypeAttribute(AnonymousType

Deserializing XML with unknown fields - what will happen?

断了今生、忘了曾经 提交于 2019-12-24 08:48:39
问题 We have developed an application that "talks" to Microsoft Dynamics AX using XML. Unfortunately, the XML format isn't documented, but the guy working on the project before me simply extracted an XSD schema from the files, which we validate against when deserializing data from AX. The only problem we have now, is that the client frequently adds new fields in AX - which naturally breaks the schema. They want us to turn off validation altogether ("We don't want to be dependent on you every time

Serializing to XML file creates invalid XML document (11,12) [duplicate]

三世轮回 提交于 2019-12-24 08:22:10
问题 This question already has an answer here : FileMode.Open and FileMode.OpenOrCreate difference when file exists? c# bug? (1 answer) Closed last year . I'm trying to save a class into an XML Document. The class looks Like this: public class Settings { public LDAP LDAP; public Miscellaneous Miscellaneous; } public class LDAP { public bool LoadLDAPData; public bool ShowLDAPRoutingMessage; } public class Miscellaneous { public bool MinusBeforeQuestion; public bool MinusBeforeDescription; } The

Multiple Names for XML Elements and Attributes

﹥>﹥吖頭↗ 提交于 2019-12-24 07:56:46
问题 NOT A DUPLICATE OF THIS: This has been flagged as a duplicate of the link that I added to an existing StackOverflow Question and Solution. This is not a duplicate as that question specifically deals with XmlElements. I am looking for a way to mould that solution to work with XmlAttributes as well as XmlElements. I am building a Class Library that interacts with Web Service that returns XML. This Web Service is attached to a Document Management System. I have built an object for each type of