简体   繁体   中英

Deserializing a legacy XML structure in xstream

I'm trying to deserialize an xml structure that looks like this:

<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. Anyone know how to do this with 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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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