标签:java cts 操作 catch tac element map blog elements
1、将对象转换成xml,需要先导入XStream jar包,下载地址:http://x-stream.github.io/download.html
XStream xs = new XStream(); String xmlStr= xs.toXML(obj);
2、将对象转换成xml,并用流输出
XStream xs = new XStream(); xs.toXML(obj,outputStream);
3、将xml转换成map,需要先导入dom4j jar包,下载地址:https://sourceforge.net/projects/dom4j/files
Map<String, String> map = new HashMap<String, String>();
SAXReader sr = new SAXReader();
Document doc = null; try { doc = sr.read(inputStream); } catch (DocumentException e) { e.printStackTrace(); } Element root = doc.getRootElement(); List<Element> elements = root.elements(); for (Element element : elements) { map.put(element.getName(), element.getText()); }
标签:java cts 操作 catch tac element map blog elements
原文地址:http://www.cnblogs.com/2333/p/6404224.html