get xml as string instead of class with xstream(获取 xml 作为字符串而不是使用 xstream 的类)
问题描述
我有类似 xml 的东西
I have xml something like
我需要将 message 表示为 String ,而不是在父对象中创建消息对象.所以,当我做 parent.message 时,输出是 <type>15 </type>
而不是消息对象.
Instead of creating a message object inside parent object, I need to represent message just as a String . So , when I do parent.message , the output is <type> 15 </type>
instead of a message object.
推荐答案
idia是通过处理HierarchicalStreamReader
来构建消息的xml.如果您通过调用 reader.goDown()
进入 <messsage>
不幸的是 reader.getValue()
不会返回的全部内容这个元素.
The idia is to build up the xml of message by processing the HierarchicalStreamReader
. If you go down into <messsage>
by calling reader.goDown()
unfortunately reader.getValue()
does not return the whole content of this element.
型号
转换器
这个测试
打印出来
但内容并不完全相同!它忽略例如空格, <foo></foo>
将映射到 <foo/>
并且我没有测试像 这样的 XML 实体'
等
But it is not every the same content! It ignores for example whitespaces, <foo></foo>
would mapped to <foo />
and I don't tested XML entities like '
etc.
也许最好将您的消息包含在 CDATA 标记中?喜欢
Maybe it's better to enclose your message in CDATA tags? Like
这篇关于获取 xml 作为字符串而不是使用 xstream 的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!