首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

castor框架应用

2012-12-20 
castor框架使用xml字符串转成JAVA对象字符串中有中文问题造成xml解析不完整下面给出转换代码:(其它配置详

castor框架使用
xml字符串转成JAVA对象

字符串中有中文问题造成xml解析不完整
下面给出转换代码:(其它配置详见castor doc)
public static Object xmlToObject(String xml,String mappingFile){
         Mapping map = new Mapping();
         Object object=null;
         try {
             map.loadMapping(CastorUtil.class.getResource(mappingFile));
             Unmarshaller unmar = new Unmarshaller(map);
             object = unmar.unmarshal(new InputSource(new StringReader(xml)) );
             Marshaller marshaller = new Marshaller(new OutputStreamWriter(
                     System.out));
             marshaller.setMapping(map);
             marshaller.marshal(object);
           
         } catch (Exception e) {
             e.printStackTrace();
         }
       
         return object;
    }

热点排行