开发者

How do I decompress this XML in .NET?

I have a .NET MVC application that returns XML by serializing the view model using a DataContractSerializer and XMLDictionaryWriter. The response is the XML below.

In this example, notice that there are 2 copies of the same "Note" object. The first time the note appears, it is perfect. The second time, all of the strings have an "i:nil" attribute and a reference to the prior node where the same string appeared.

Questions:

  • I assume this is some sort of compression. Where is this happening? In IIS?
  • How do I decompress this in .NET?

Thanks for your help!

Tom

<Note z:Id="2">
<DateCreated>2011-03-16T11:22:30.2226663-07:00</DateCreated>
<DateModified>2011-03-16T11:22:30.2226663-07:00</DateModified>
<Deleted>false</Deleted>
<PinnedToList>true</PinnedToList>
<PinnedToTile>false</PinnedToTile>
<Revision>1</Revision>
<TagText z:Id="3">#todo #work</TagText>
−
<Tags z:Id="4" z:Size="2">
−
<Tag z:Id="5">
<TagName z:Id="6">todo</TagName>
<UserId>3</UserId>
</Tag>
−
<Tag z:Id="7">
<TagName z:Id="8">work</TagName>
<UserId>3</UserId>
</Tag>
</Tags>
<Text z:Id="9">This is a sample note.</Text>
<User i:nil="true"/>
<UserId>0</UserId>
</Note>
−
<Note z:Id="10">
<DateCreated>2011-03-16T11:22:30.2226663-07:00</DateCreated>
<DateModifie开发者_如何学Cd>2011-03-16T11:22:30.2226663-07:00</DateModified>
<Deleted>false</Deleted>
<PinnedToList>true</PinnedToList>
<PinnedToTile>false</PinnedToTile>
<Revision>1</Revision>
<TagText z:Ref="3" i:nil="true"/>
−
<Tags z:Id="11" z:Size="2">
−
<Tag z:Id="12">
<TagName z:Ref="6" i:nil="true"/>
<UserId>3</UserId>
</Tag>
−
<Tag z:Id="13">
<TagName z:Ref="8" i:nil="true"/>
<UserId>3</UserId>
</Tag>
</Tags>
<Text z:Ref="9" i:nil="true"/>
<User i:nil="true"/>
<UserId>0</UserId>
</Note>


That is DataContractSerializer working in full-graph mode. It isn't compressed - that is simply the format is uses to preserve object references. Turn on full-graph mode when deserializing and it should work. That is a constructor argument to DataContractSerializer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜