简体   繁体   English

在xstream中反序列化旧式XML结构

[英]Deserializing a legacy XML structure in xstream

I'm trying to deserialize an xml structure that looks like this: 我正在尝试反序列化如下所示的xml结构:

<somecontainer>
    <key1>Value1</key1>
    <key1>Value2</key1>
    <key2>Value3</key2>
    <key2>Value4</key2>
</somecontainer>

I can basically choose what kind if element to deserialize to, maybe something like a List of Pair or something. 我基本上可以选择要反序列化的元素类型,例如“成对列表”之类的东西。 The essence here is that the element names are the keys. 这里的本质是元素名称是键。

And no, I cannot change the xml structure. 不,我无法更改xml结构。 Anyone know how to do this with xstream ? 有人知道如何使用xstream吗?

我已经有一段时间没有使用XStream了,但是隐式集合可能可以满足您的要求。

I have found that a custom serializer is needed for this case, no way around it. 我发现这种情况下需要自定义序列化器,没有办法解决。

Similarly 相似地

<node attr1="xxx">value1</node>

also needs a custom serializer. 还需要一个自定义的序列化器。

You might also consider doing an XSL transformation of the document to a normalized form before deserializing it. 您还可以考虑在反序列化文档之前对文档进行XSL转换为规范化形式。 That would obviate the need for a custom serializer. 这将消除对自定义序列化程序的需要。

I guess the trade off is if it is easier to maintain a custom serializer or an XSL transformation step? 我想要权衡的是,维护自定义序列化程序或XSL转换步骤是否更容易?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM