xml与对象的转换

前端之家收集整理的这篇文章主要介绍了xml与对象的转换前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1Stringstr=“xmlg格式的标签

自定义对象AA中封装的属性为xml中的标签


MonitorShowUtil monitorShowUtil=MonitorShowUtil.getInstance();


MonitorShowUtil:

public class MonitorShowUtil {
private static MonitorShowUtil _self=new MonitorShowUtil();

private XStream monitorShowXStream = new XStream(new DomDriver("utf-8"));
{

monitorShowXStream.alias("config",MonitorShowPageVO.class);//为MonitorShowPageVO类创建别名config
monitorShowXStream.alias("serviceVO",ServiceVO.class);
monitorShowXStream.alias("gridVO",GridVO.class);

}
public static MonitorShowUtil getInstance() {
return _self;
}
/**
* 转换为XML
* @param obj
* 对象
* @return
*/
public String monitorShowXStreamToXml(Object obj){
return monitorShowXStream.toXML(obj);
}
/**
* 转换为对象
* @param xml
* XML
* @return
*/
public Object monitorShowXStreamFromXml(String xml){
return monitorShowXStream.fromXML(xml);
}
}


Aa=(A)monitorShowUtil.monitorShowXStreamFromXml(str);//把xml文件转为了自定义的对象


原文链接:https://www.f2er.com/xml/294852.html

猜你在找的XML相关文章