Jump to content

  • Log In with Google      Sign In   
  • Create Account


format of xml serialization


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 dworm   Members   -  Reputation: 334

Like
0Likes
Like

Posted 02 February 2014 - 04:59 PM

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)


Sponsor:

#2 exOfde   Members   -  Reputation: 808

Like
1Likes
Like

Posted 03 February 2014 - 12:53 AM

What did you want to serialize? Perhaps it has to look like this!

#3 dworm   Members   -  Reputation: 334

Like
0Likes
Like

Posted 03 February 2014 - 02:55 AM

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>


#4 exOfde   Members   -  Reputation: 808

Like
1Likes
Like

Posted 03 February 2014 - 03:51 AM

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.

#5 dworm   Members   -  Reputation: 334

Like
0Likes
Like

Posted 03 February 2014 - 08:36 AM

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..



#6 exOfde   Members   -  Reputation: 808

Like
0Likes
Like

Posted 03 February 2014 - 12:28 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS