我有一些xml代码,我想将它解析为java对象,请帮助我。
<Error>
<number>1020</number>
<Type>fatal</Type>
<Text>Nagaraju</Text>
<Text>Suresh</Text>
<Text>Sound</Text>
<Text>Rajesh</Text>
</Error>
java对象是
Class Error{
int number;
String type;
List<String>texts=new ArrayList<String>();
}
答案 0 :(得分:5)
我会亲自手动映射,或者也许使用JAX-B,但如果你真的想使用XStream:
答案 1 :(得分:-1)
使用代码:
String response = "<\patron_tenders><\patron_tender name=\"alpha\" city=\"mumbai\" >"
+ "<\partial_card_number>************6319<\partial_card_number>"
+ "<\zip_code>123456<\zip_code>"
+ "<\tender_type_name>Visa<\tender_type_name>"
+ "<\token_id>80195<\token_id>" + "<\expired>false<\expired>"
+ "<\patron_tender>"+"<\patron_tender name=\"beta\" city=\"pune\" >"
+ "<\partial_card_number>************3545<\partial_card_number>"
+ "<\zip_code>565768<\zip_code>"
+ "<\tender_type_name>Visa2<\tender_type_name>"
+ "<\token_id>83397<\token_id>" + "<\expired>true<\expired>"
+ "<\patron_tender><\patron_tenders>";