使用 Xstream 获取动态内容
我正在尝试使用 Xstream 处理一个特殊的场景,其中 XML 的部分结构事先不知道。
我可以成功序列化/反序列化其结构预先已知的 xml。
例如:
<MemberList>
<Member id="1">
...
</Member>
<Member id="2">
...
</Member>
</MemberList>
但是对于下面的片段,我们不知道上下文元素中可以包含什么。显然,我们不能让 xstream 如何映射此元素内的元素。
<MemberList>
<!-- Structure not known for this element -->
<Context>
<!-- can contain any arbitrary xml whose structure not known in advance -->
</Context>
<Member id="1">
...
</Member>
<Member id="2">
...
</Member>
如何从反序列化对象中重现准确的 xml,并将 Context 元素及其内容准确复制回序列化 xml 中。
I am trying to deal with a special scenario with Xstream where the XML structure is not know in advance for part of xml.
I could successfully serialize/deserialize xml whose structure is known advance.
For eg:
<MemberList>
<Member id="1">
...
</Member>
<Member id="2">
...
</Member>
</MemberList>
But for below fragment, we don't know what all can come inside context element. And obvisouly, we could not let xstream, how to map elements inside this element.
<MemberList>
<!-- Structure not known for this element -->
<Context>
<!-- can contain any arbitrary xml whose structure not known in advance -->
</Context>
<Member id="1">
...
</Member>
<Member id="2">
...
</Member>
How can I reproduce the exact xml back from deserialized object, with Context element and its contents exactly copied back in serialized xml.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论