解析xml,OjbectTree转xml

来源:互联网 发布:数据做预测的方法 编辑:程序博客网 时间:2024/05/29 03:32

import com.thoughtworks.xstream.XStream;

  /**
     * Filter object attributes based on API and permission
     *
     * @param object
     * @param apiName
     * @param groupList
     * @return
     * @throws Exception
     */
    public String marshal(Object object, String apiName, List<String> groupList) throws Exception{
        XStream xStream = newXStream(apiName, groupList);

        /**
         * Modified on April 16 to remove &#x0; from generated xml string that cannot be parsed by gwt xml parser
         */
        String resultXml = xStream.toXML(object);
        if (resultXml != null){
            resultXml = resultXml.replaceAll("&#x0;", "");
        }
        return resultXml;
    }

 

 

    /**
     * Marshal object into xml string
     *
     * @param object
     * @return
     * @throws Exception
     */
    public String marshal(Object object) throws Exception{
        return marshal(object, null, null);
    }

 

 

     /**
     * Unmarshal xml string to objects
     *
     * @param xmlString
     * @return
     * @throws Exception
     */
    public Object unmarshal(String xmlString) throws Exception{
        XStream xStream = newXStream(null, null);
        return xStream.fromXML(xmlString);
    }

原创粉丝点击