2
我正在使用com.thoughtworks.xstream.XStream來生成XML字符串。我將Object解析爲xstream。 toXML方法,並根據我需要的方式得到xml輸出。XStream撇號將Java對象轉換爲XML的問題
<myxml>
<test type="test" name="test">
<question id="Name" answer="Micheal"/>
<question id="Address" answer="Home">
<details name="First Address">
<detailanswer>friend's House</detailanswer>
</details>
</basequestion>
</test>
</myxml>
XStream xstream = new XStream();
xstream.alias("myxml", MyXml.class);
xstream.alias("test", Test.class);
xstream.alias("question", Question.class);
xstream.alias("details", Details.class);
xstream.alias("detailanswer", String.class);
xstream.addImplicitCollection(MyXml.class, "test");
xstream.addImplicitCollection(Test.class, "question");
xstream.addImplicitCollection(Question.class, "details");
xstream.addImplicitCollection(Details.class, "detailanswer");
xstream.useAttributeFor(Test.class, "type");
xstream.useAttributeFor(Test.class, "name");
xstream.useAttributeFor(Question.class, "id");
xstream.useAttributeFor(Question.class, "answer");
xstream.useAttributeFor(Details.class, "name");
return xstream.toXML(eform);
以下是對象結構。
Inside MyXml there is List<Test>
Test has List<Question>, String type, String name
Question has List<Details>, String id, String answer.
Details has List<String> detailAnswer, String name
所以在問題的元素,朋友的房子被添加到列表中detailAnswer詳細類。
我得到friend's House
而不是friend's house
。我該如何解決這個問題。有沒有特別的方法使用XStream進行轉換?
也給你的POJO代碼。 – 2014-10-07 08:47:15
更新了問題 – 2014-10-07 08:59:47
'''與XML中的'''意思相同,所以它不是真的_wrong_,只是不同而已。嘗試一個替代的XStream驅動程序,比如'StaxDriver',看看它是否有幫助。 – 2014-10-07 09:18:14