Click here to Skip to main content
15,888,283 members
Everything / XmlSerializer

XmlSerializer

XmlSerializer

Great Reads

by Dirk Bahle
Tips & Tricks on De/Serializing object graphs with XML
by Shaun C Curtis
How to quickly generate code to handle XML files with an XSD definition
by Maciej Los
If you want to know the way you can serialize and deserialize custom class collection, this tip is for you.

Latest Articles

by Shaun C Curtis
How to quickly generate code to handle XML files with an XSD definition
by altomaltes
This code allows dumping and retrieval from a single variable to a complete tree of objects using both JSON and XML, in an unintrusive way, using tentative templates.
by Dirk Bahle
Tips & Tricks on De/Serializing object graphs with XML

All Articles

Sort by Score

XmlSerializer 

22 Dec 2017 by Dirk Bahle
Tips & Tricks on De/Serializing object graphs with XML
1 Dec 2020 by Shaun C Curtis
How to quickly generate code to handle XML files with an XSD definition
19 Jun 2014 by Maciej Los
If you want to know the way you can serialize and deserialize custom class collection, this tip is for you.
7 May 2015 by Sergey Alexandrovich Kryukov
This is nonsense. XML document, by definition, has one and only one root. If you remove the root, the next level of hierarchy can be one element of more than one. If there is only one element, removing root will give you valid XML (or at least well-formed). This is not the case in your example,...
7 May 2015 by Maciej Los
If you want to skip root element and get only child nodes, use this:var invoices = xdoc.Root.Elements();Now, you can "convert" it into json object.Note, that using your code you'll get something like this:{"ExtSerial":"KDI2015050501"},{"Date":"02/01/2015"},...but...
29 Oct 2015 by BillWoodruff
Quote: how to initialize and assign values multiple address and phone number.There are several ways you can initialize/assign to whatever Collection data-structure you select to hold the multiple values. Here's an example that reflects the way I like to work:public enum PhoneType{ ...
17 Apr 2016 by Patrice T
The problem may be that your XML file is not an XML file.Otherwise, using the debugger will show you exactly what is going on.
20 Dec 2019 by Richard Deeming
There's a syntax error in your XML: the element is self-closing, but it also has a closing tag. Quote: The 'EXPORT_HEADER' start tag on line 2 position 2 does not match the end tag of 'TRANSACTION'. Line 4, position 5. Once that's fixed, your "What I have tried" code works to...
17 Mar 2014 by Vedat Ozan Oner
you can make your array 'a' sorted. List a = g.ToList().Select(i=>int.Parse(i)).OrderBy(i=>i);List missings=new List();int idx=0; // a indexfor(int i=0; i
20 Mar 2014 by ZurdoDev
I would use the XDocument or you could also use the XmlDocument. The XDocument is newer and supports Linq.http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument_methods(v=vs.110).aspx[^]You can use Elements() or Descendants() etc.
29 Mar 2014 by Sergey Alexandrovich Kryukov
This is the XML Schema file. Please see: http://msdn.microsoft.com/en-us/library/04x694fe%28v=vs.110%29.aspx[^].—SA
12 May 2014 by dan!sh
You will need to create a Serializable class that represents this XML format and then use XMLSerializer class and its methods to get the object.You can use XSD.exe to create class that will represent this XML.
20 May 2014 by Maciej Los
Start here: Introducing XML Serialization[^] and follow the links on your left ;)
13 Aug 2014 by Yogesh Kumar Tyagi
view this link for mvc tree view How to Create TreeView in MVC3[^]i think it will help you.Build a custom MVC Tree Control by using jsTree[^]
26 Nov 2014 by Joezer BH
Should be fairly simple.Try creating the XmlSerializer with the constructor that also takes XmlRootAttribute// Fix this line of code, use the costructor that follows : XmlSerializer(Type, XmlRootAttribute)XmlSerializer xmlSerializer = new XmlSerializer(typeof(TimeProjects));// try...
15 Dec 2014 by D Sarthi Maheshwari
If your issue is just to get the fragment. One way of doing this is:var reader = XmlReader.Create(YOUR_SERIALIZED_FILE_NAME);reader.Read();reader.ReadToFollowing(NODE_NAME);Then use either reader.ReadOuterXml() or reader.ReadInnerXml() as per ur requirement.Hope this would help.
27 Mar 2015 by Mario Z
Hi, well I see you have successfully retrieved the desired XmlNode. All that is left for you is to retrieve the required attribute from that node.So something like this:Dim bookAmoount = Book.Attributes("amoount").ValueAlso just in case you're interested you can simplify your code with...
20 Apr 2015 by Maciej Los
Wikkipedia wrote:XML validation is the process of checking a document written in XML (eXtensible Markup Language) to confirm that it is both well-formed and also "valid" in that it follows a defined structure. A well-formed document follows the basic syntactic rules of XML, which are the same...
29 Oct 2015 by Maciej Los
I'd suggest to read:XML Serialization and Deserialization: Part-1[^]XML Serialization and Deserialization: Part-2[^]A Complete Sample of Custom Class Collection Serialization and Deserialization[^]
8 Sep 2016 by ZurdoDev
Perhaps is a required field. The error is very clear. The code is trying to convert something you sent it into a DateTime and what you sent is not a valid DateTime. However, since none of us, including you, can see the webservice code I'm not sure what you want from us.You'll have to...
13 Mar 2017 by CHill60
This CP article should help you along: XML Serialization and Deserialization: Part-2[^]
10 Nov 2017 by Graeme_Grant
The Xml is poorly formed, the code sample uses classes not defined, and there is no mention of what issues that you are having with which line of code. Here is the XML fixed:
12 Dec 2017 by Leo Chapiro
You can simple split the XML string by blank and remove the part with "xmlns:xsd": string strXml = ""; string[] ar = strXml.Split(' '); string strResult = string.Empty;...
4 Feb 2018 by Maciej Los
KumarAbhishekJaiswal - Professional Profile[^] wrote: it does not look like any traditional XML You're wrong. This xml has proper form. See: XML attributes[^]. I did exactly what is described here: c# - How to Deserialize XML document - Stack Overflow[^] and the classes generated by xsd.exe...
27 Feb 2018 by Graeme_Grant
Firstly, you have an error in the XML data sample on line# 443. I would map classes to the XML data and convert. But it you want to manually read the xml data, then you could do something like this: var doc = XDocument.Parse(rawXml); var products = doc.Descendants() ...
29 Mar 2022 by Richard Deeming
Seems simple enough using LINQ to XML[^]: // Values to find: string pin0 = " value0 ", pin1 = null, pin2 = " value2 ", pin3 = null; XDocument document = XDocument.Load("load.xml"); var select = doc.Descendants("Select").Select(s => new { ...
7 Oct 2013 by vinu2528
Hello friendsPlease help me to create a class so that after serialization i will get a xml of format this: GOOD 200 09/02/2004...
7 Oct 2013 by Sergey Alexandrovich Kryukov
If you want the most comprehensive solution which is the easiest to use at the same time, don't use XmlSeializer, use Data Contract instead:http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].Please see also my past answers where I advocate this approach:Creating property...
14 Dec 2013 by Member 4479742
Hi i stored class object in logical data(call context) ,when i try to access the logical data(call context) from different app domain,I'm getting system.runtime.serialization issue. Following my code will reproduce my issue . public static class Program { private...
27 Jan 2014 by Daniel Balogh
Dear all, Please forgive me if my terminology isn't accurate, it's a new field for me. :)I have implemented a class in VB which is serialized to xml (actually the xml-file will be deserialized to the class, however)So the XML:
28 Jan 2014 by Kornfeld Eliyahu Peter
Dictionaries of .NET are not serialize-able, so you have to implement it yourself...public class Property{ public K Key { get; set; } public V Value { get; set; }}public class Person{ public Person ( ) ...
7 Mar 2014 by Divakar Raj M
I generated a XML Serialization using the following C# codepublic class Program { static void Main(string[] args) { AddressDirectory addr = new AddressDirectory(); Address A1 = new Address(); A1.City = "Chennai"; ...
7 Mar 2014 by Vedat Ozan Oner
I have changed your code a little bit:using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Xml.Serialization;namespace Test_XmlSerialize2{ public class Program { static...
17 Mar 2014 by KUMAR619
I can use Xml writer to write any Xml document but can we write again using Xml Writer.If so how to do this
17 Mar 2014 by KUMAR619
I want to check whether all the XML element in the XML file are located in ascending order or not.I want to check them through an attribute called ID.Is there any way to do soHow to do so.string[] g = new string[count]; for (int i = 0; i
20 Mar 2014 by KUMAR619
I am having an XL file having several nodes of same name.I want to select these nodes one by one for further purpose.
10 Jun 2014 by Kornfeld Eliyahu Peter
I can't understand why you are using some 3rd party extension to serialize an object to XML, but if this is a requirement then go and ask the 3rd party for support!If you can choose your way, than you be better with the simple .NET way of XML serialization (and deserialization)...Start...
12 Jun 2014 by IshaqSalam
I was make web services. this is my code.vb filePublic Class xlogin _ Public StatusID As Boolean End Class _ Public Function Login(ByVal sUser As String,...
21 Jul 2014 by Riccardo Macaluso
Hi guys! I have to ask you help for XML serialization.I have to deserialize this XML document (a piece of electronic invoice): IT 12345689 ...
21 Jul 2014 by Maciej Los
Here, on CP site, you'll find several articles about serialization and deserialization of XML. Please, use SearchBox[^] on the right-top corner of this site, for example: A Complete Sample of Custom Class Collection Serialization and Deserialization[^]
4 Aug 2014 by Anshumaan Chaturvedi
I have an XML file consisting of an element "Settings". All the rest of the elements are getting populated in DataTable but settings.While reading in the XML file this is the reference code i implemented.But the breakpoint is not hitting the "Settings" case.foreach (DataRow drow in...
12 Aug 2014 by angiangi
I'm trying to get nested hierarchy data from large XML file and show it in a tree structure in MVC application.I need to considerate performance issue as well, because I'm using a large xml file.I started with parsing the xml with XmlReader and now i thinking to use XmlSerializer, what do...
31 Aug 2014 by Nicola Ramoso
Hi everyone,I'm currently dealing with an XML file structured like this: ...
1 Sep 2014 by George Jonsson
I can't see the screen shot, but here are some questions for you that might help your trouble shooting: 1. Is it when you de-serialize the data that the error occurs? If so, have you tried to open the document in an XML viewer? Maybe you will get some hints if an error...
3 Oct 2014 by BrooksV2
One method for reading and parsing XML data is to use System.Xml.XmlTextReader(). This will allow you to extract out exactly what you need from the XML.This code example will demonstrate the basics of finding Elements and attributes. Since your situation doesn't require retrieving Attribute...
28 Oct 2014 by Hein_vdw
I have created a rest service and it is working perfectly with my get operation, but i am trying to implement a POST, but when the xml data reaches the service it looks like this (missing half the objects and priority changes to 0 instead of 8888) :
28 Oct 2014 by Hein_vdw
Ended up using a DataContractSerializer instead of a xmldocument from the clientside
26 Nov 2014 by ToShX
Hey,I have the problem, that I have to serialize multiple objects of the same type to a xml-file with the XmlSerializer-Class. But I'm only able to create xml-files like this one here: A 0 0 ...
26 Nov 2014 by Sergey Alexandrovich Kryukov
How about not dealing with XML manually at all? The best XML serialization is implemented using the Data Contract:http://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^].Please see my past answers where I advocate this approach:How can I utilize XML File streamwriter and...
26 Nov 2014 by Er. Dinesh Sharma
Hi Please try this Codepublic class MakeSer { public MakeSer() { TimeProject tm = new TimeProject(); Projects[] proj = new Projects[2]; proj[0] = new Projects { Comment = "X", name = "Y", TimeToday = "40", TimeTotal = "10" }; ...
6 Apr 2020 by PeejayAdams
I want a way to serialise generic objects into XML fragments.The fragments will be inserted into other XML documents and as such, I require a result that would look something...
10 Jan 2015 by Md Athaulla
Hello,Using below code im creating the xml file. My requirement is to create/update XML file , if item already exists then i need to update the item else i need to add that element.XmlSerializer serializer = new XmlSerializer(typeof(ReleaseChangeModel));Stream fs = new...
10 Jan 2015 by BillWoodruff
Do you know how to read an XML file into "objects" (create a XmlDocument ... or DOM ... from the XML) ? That's what you will need to do to change a specific property or state; and then, you'll need to save the changed DOM back to the file to update the file.I suggest you start by doing some...
12 Jan 2015 by Md Athaulla
Thanks alot for your kind reply. i have checked the links they are helpful. But My requirement is similar to logging into file. There is some problem in xml writing in the current code. First time it will write, second time if I try to write the title in xml, it is writing out of element.I have...
17 Mar 2015 by Member 10294936
How deserialize document XML: --------------------------------------------- 1 1 5 ...
18 Mar 2015 by Maciej Los
I'd suggest to use xsd.exe tool[^] which can generate proper class(es) definition from xml.Follow these steps: Auto generating Entity classes with xsd.exe for XML Serialization and De-Serialization[^][EDIT]I'd suggest to change your XML structure: ...
26 Mar 2015 by Sergey Alexandrovich Kryukov
Parse it is appropriate data structure first, or use XML serialization, or use LINQ To XML.—SA
26 Mar 2015 by Member 11491784
30 Mar 2015 by Member 10420430
How to change the elements name depending on condition.e.g Class Section{[XmlAttribute(AttributeName = "name")]public string Name{get;set;}[XmlElement(ElementName = "question")]public ListQuestion{get;set;}} Class Question{public int...
20 Apr 2015 by Lalyka
I want to send a http request from client to local server and on the server I made a query with Linq that returns data in xml I also have .xsd file and a .cs file enerated from my xsd file that I want to validate my xml with. I have several questions:how can I validate xml with c# generated...
23 Apr 2015 by Sethi1978
I made a self-hosted web service in c# and everything works fine.I work on this base Object class (DevExpress XPO): [Persistent(System.StatusTable)] public class XPStatusTable : XPBaseObject { private short fIDTable; [Key(true)] public short...
28 Apr 2015 by Leo Chapiro
Basically take a look at this answer:Use XML reader instead of XML dom. XML dom stores the whole file in memory which is totally useless: XmlReader ClassYour second question:Quote:How to use/access "private ATXARPACKAGE[] aRPACKAGESField" Why have you made this variable...
28 Apr 2015 by Mehdi Gholam
Start here : http://stackoverflow.com/questions/15772031/how-to-parse-very-huge-xml-files-in-c[^]https://msdn.microsoft.com/en-us/library/bb387013.aspx[^]
7 May 2015 by Joshua Masa
I'm trying to serialize XML to JSON. Getting the XML from a file location and running it to a foreach statement to serialize. But the thing is the output of the json is{"ExtSerial":"KDI2015050501"}{"Date":"02/01/2015"}{"CustomerRefNbr":"15-000001"}{"Description":"2015 FEBRUARY...
7 May 2015 by Maciej Los
Have a look at past answer: remotly convert xml to json in asp.net mvc[^]
25 May 2015 by Mohammad Adi
"here url xml"**And it's my controller** [HttpGet] public JsonResult getXMLrequest() { var response = new HttpResponseMessage(); var urlDJP = Request.QueryString["urldjp"]; var data = new VatInRecieveModels(); ...
18 Jun 2015 by Priyatam Upadrasta
someclass objsomeclass = new someclass ();objsomeclass.portalServiceInput = new portalServiceInput();objsomeclass.portalServiceInput.bank_Account_Number = "12563";objsomeclass.portalServiceInput.bank_Finance_Details = "145263";objsomeclass.portalServiceInput.bank_Finance_Reqd =...
18 Jun 2015 by Icoon
Did you already checked this article: https://msdn.microsoft.com/en-us/library/58a18dwa%28v=vs.110%29.aspx[^]
13 Jul 2015 by Member 11684783
Dear Folk,i got a fine working XMLSerializer for a sophisticated List of 3D model with many different elements. Now i want to serialize another List beside of that, that only saves few Elements of it. I just tried to bar some of them out with [XMLIgnore] but this causes problems in my...
31 Aug 2015 by meliti
hiwhy this cod have error when generat the xml document?plz help metanx private void CreateForm() { DForm form1 = new DForm() { Name = "Form1" }; DPage page1 = new DPage() { PageNumber = 1 }; DPage page2 = new DPage() { PageNumber = 2 }; ...
14 Oct 2015 by Member 10918596
System.InvalidOperationExcepti...
28 Oct 2015 by sunsuhesh
I have three classes: person, address and phone. A person can have multiple addresses and each address has phone numbers. Here how to initialize and assign values multiple address and phone number. Below is my class model.public class Person{ public string Name { get; set; } ...
16 Nov 2015 by Raseeth90
public string XmlSerializer(Object item){ StringBuilder builder = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Indent = true; using (XmlWriter xmlWriter = XmlWriter.Create(builder,...
17 Nov 2015 by Henrik Jonsson
One option is to perform some post-processing of the output using regular expressions:First define the following Regex to find the empty tags:static Regex emptyElementRegex = new Regex(@"");Then process your output to replace all matching occurrences:var result =...
22 Nov 2015 by PuchuKing33
Hello everyoneI am working on a WPF project, where i want a user to be able to insert a string into a combobox (is set to IsEditable) and save the string into an XML file. At the same time the saved string/strings has to be shown when the combobox is dropped down (also when the project is...
22 Dec 2015 by snziv
I have this query, can we do CRUD operation on XML using Serialization and Deserialization (using system.xml.serialization library )I know it can be done using other libraries like xmldocument,XMLWriter but just curious to know whether is there any way that we can perform CRUD using...
24 Feb 2016 by satrio_budidharmawan
Hi, I am newly working with XML files with C#, currently I am facing a problem about editing a specific value from XML file.Let's say I have this XML file (plist.xml) : Dominic Crossroad Android ...
24 Feb 2016 by Manas_Kumar
Try with below code:string xmlData = @" Dominic Crossroad Android 1522 dominicroad 1.0.0, 1.2.0i, 2.0.0j
14 Mar 2016 by Renjith Kalarikkal
Hi I am getting the response from an API as
14 Mar 2016 by Manas_Kumar
Use Xml.Linq to get required values. Try with below code:string temp = @"";XDocument doc = XDocument.Parse(temp);var tempobj = (from rec in doc.Descendants("VCNAuthItem") select new { TxnId = rec.Attribute("TxnId").Value, SystemDate =...
14 Mar 2016 by F-ES Sitecore
foreach (XmlNode node in xDoc.SelectNodes("/Items")){ foreach (XmlNode itemNode in node.SelectNodes("VCNAuthItem")) { string alias = itemNode.Attributes["VCardAlias"].InnerText; }}
17 Apr 2016 by saraswathi
May be the conversion from the xml to the object is not happening properly. Do you have access to the logistics class? Can you check how the Deserializer deserializes your freightrate and OffshreDelivery properties from the xml to object or what ever type they are? by that i mean what is the...
20 Apr 2016 by sahmed3
I have updated the code as below public ActionResult GetLogisticsReport(int StoreId) { StoreId = 00316; try { XmlDocument xmlDoc = new XmlDocument(); string LogisticsReportResponseXml =...
31 May 2016 by George Jonsson
Instead of nillable="true"tryminOccurs="0"This will leave out the element all together. Test
31 May 2016 by PraveenDora
Hi Lalykayou can handle in two ways .. either set default value in XSD oryou can initialise those class variables to empty string RegardsPraveen
12 Jul 2016 by ebie147
hi guys so i got a datagridview that has a dataset that is linked to a xml file,I got to display the data in the datagridview but what i want to do now is take out rows that has certain values,this is my code'Load Creditors data Dim CPADataset As New DataSet Dim...
8 Sep 2016 by Soft009
Hi,I have developed a webservice client using c#. Using client I am going to call 3rd party web service developed using java.But when I run the application I am getting exception as "Quote:Error in deserializing body of reply message for operation 'QueryUserProfile'. and the Inner...
19 Jan 2017 by Member 12805031
I am looking to get vbscript to load soap xml file from one of the table columns (CLOB type). In this xml, we are searching for ' character under a child tag within parent tags.Below is...
19 Jan 2017 by Leo Chapiro
Use XPath / DOM for parsing XML in VBScript: XML Files - XML Tutorial - Microsoft XML Parser[^] One very common way to extract XML elements from an XML document is to traverse the node three and extract the text value of each elements. A small snippet of programming code like a VBScript...
24 Feb 2017 by Member 11748288
hi i have two class foo and wrappersfoo is my original class and i create a list from foo class and wrappers class decorate with [serializable] and [xmlelement(ElementName=)]this is my foo class public class foo { public string Name { get; set; } public...
24 Feb 2017 by Graeme_Grant
What you want doesn't seem to be too standard, XML explicitly disallows numbers (and some other things) as the first character of an element name:NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | ...
2 Mar 2017 by Praveen Behera
Hello guys,This is my first time in the site, so possibly i am unsure how to ask questions. Still here it is -I have an excel file containing xml files in oledb object form.What i need is, how can i get the label and file path of that xml file stored in oledb using C#.Note:...
13 Mar 2017 by Pragya Nagwanshi
I have to create class of these xml file.Label Label1 label 20 30 35 13 True True...
14 Mar 2017 by Amien90
using (StreamWriter file = File.CreateText(@"c:\test\source.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, eList); }I use this to write my JSON Object to a json file. But is it easy with some...
14 Mar 2017 by Graeme_Grant
The answer is yes and no. It depends on how the data is to be serialized.I have two Converter classes, one for JSON & one for XML. Both are called the same way, so easy to switch. I'll post both below. The XML version has additional information that should be self-explanatory.JSON...
14 Mar 2017 by F-ES Sitecore
System.Xml.Serialization.XmlSe...
8 May 2017 by Member 2127939
The code below currently works and loads XML into a class structure. This structure consists of a collection of items (items), each that have fixed properties and a collection that I use for a variable number of properties. Two things I want to do: 1) I want to change the list into something...
8 May 2017 by Richard Deeming
Assuming the elements in your XML file are actually cased correctly, and the missing closing elements are present, you just need to change the type of your KVPS property from: List> to List> You're currently using the built-in...