1Stringstr=“xmlg格式的标签”
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文件转为了自定义的对象