Sign in to follow this  
dworm

format of xml serialization

Recommended Posts

dworm    683

i really cant understand how to change things here... im trying to serialize some class into xml using DataContractSerializer

 

But i get this kind of format:

 

<ArrayOfItemType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="ItemType">
<ItemType i:nil="true" />
<ItemType>
<d3p1:int>1</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
</Actions>
<ItemName>tree</ItemName>
</ItemType>
 
how to get rid of all the crap? how to avoid printint everything that is default ? ( i have [DataMember(EmitDefaultValue = false)] but apparently since it refers to an array it only emit when the whole array is null not each single member)

Share this post


Link to post
Share on other sites
dworm    683

yeah it probably has to but i dont want it to be like this... the whole point is serializing into something easy and fast to edit so i dont want any extra detail like int in the </d3p1:int> or all the zeroes

 

also i would want to be indexed so instead of

 

<d3p1:int>1</d3p1:int>

<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
<d3p1:int>0</d3p1:int>
 
i rather have something like
<action#1>1</action>
 
or <actions>1, 2, 3</actions>

Share this post


Link to post
Share on other sites
exOfde    838
From what I know you should never ever manipulate something by hand that you did serialize. But what you want sounds like you should do it save into your own xml save file format. The lib you use do its job, it serialize and deserilize. In which way it does you should normally not care.

Perhaps this could be your solution(maybe you need to change the language): http://msdn.microsoft.com/de-de/library/system.runtime.serialization.xsddatacontractexporter(v=vs.110).aspx and http://msdn.microsoft.com/de-de/library/system.runtime.serialization.formatter(v=vs.110).aspx

You could try to transform your xml document into your format you want.

Share this post


Link to post
Share on other sites
dworm    683

yes this could be a way but you know... i understood c# was supposed to not force me to rewrite a whole serialization code...

Its not really hard but its really boring and quite long if i want it to be fail safe for the future..

Share this post


Link to post
Share on other sites
exOfde    838

Only til a specific point and this only by external/own library. the language itself has nothing do with it. you cannot expect a lib do all work for you. especilly if you want a specific behaviour. For that exist e.g. inheritance , interfaces ... etc to give you the programmer the possibility the to create specific content you need with help of an external lib. And sometimes it's just boring work. that's life

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this