In this article, 2 scenarios where XML Serialization can be used togather with SQL server shall be demonstrated. XML Serialization. XML serialization serializes the public fields and properties of an object, or the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document. Convert xml into xmlserializer compatable csharp classes. Convert away! Put your Xml into the big old box below.
Active3 years, 10 months ago
In C# if I serialize an object that has a list of objects in it will it also serialize the list?
Example
If I serialize move will all the tags stored in move get serialized as well? Also if it will not serialize the list how would I go about making it do that?
Max Young
Max YoungMax Young
79711 gold badge88 silver badges3131 bronze badges
3 Answers
Yes, using the
XmlSerializer it will serialize a List<T> so long as T (or in your case Tag ) is serializable.
This outputs using your current class structure as:
I'll see if I can find a way to match your current XML schema, but you can look up how to apply XmlAttributes and play around with it yourself.
EDIT:
If you change your class declaration to use the following XmlAttributes, you will achieve the exact XML schema as in your example:
Which when serialized will produce:
Chris SinclairChris Sinclair
20.2k22 gold badges4242 silver badges7979 bronze badges
Are you sure that your class Declarations are right in your Question ? Download adobe acrobat 10 pro x. you are just declaring
Public Move , It should be Public class Move
Try this code
In Your case
OutPut
KasKas
2,35222 gold badges1717 silver badges4545 bronze badges
By default, no it won't, since the items within the list may not be serializable.
If they are, then you may find the following page userful:
Community♦
Brendan HillBrendan Hill
Not the answer you're looking for? Browse other questions tagged c#xmlserialization or ask your own question.
Active6 years, 5 months ago
I am trying to serializer an XML into an object. I am however, having some trouble. I have gone through maybe postings online regarding an answer, but I haven't been able to figure it out. Please let me explain:
I have the below XML that I want to serialise:
Im using four classes to capture this XML:
The code I use to deserialize is:
And the error I'm getting is:
Does anyone know what I'm missing here? Hope someone can help out!
Regards,
Bob
Robert BenedettoRobert Benedetto
47811 gold badge55 silver badges2525 bronze badges
1 Answer
The first obvious error is:
which should of course be:
However, you should also note that xml is case-sensitive:
should be:
to match the xml; likewise
C# Serialize To Xml
should be:
and:
should be:
Additionally, note that
<Players> is not a descendant of Import_Event - it is part of Events . This makes life a little complex.
We then note that your dates are not 'starttime' / 'endtime', so we can simplify to:
except.. those date/times are not valid xml date/times - they are in the wrong format. So you might have to treat those as
string data for now.
Finally, your xml is malformed - you have not closed the root element.
C# Xml Serialize To String
Frankly, I'm not surprised the serializer didn't like that :)
Marc Gravell
C# Serialize And Deserialize Object♦C Sharp Serialize Object To XmlMarc Gravell
825k213213 gold badges22282228 silver badges26242624 bronze badges
Not the answer you're looking for? Browse other questions tagged c#xml-serialization or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |