// 字符串转XMLString xmlStr = "";StringReader sr = new StringReader(xmlStr);InputSource is = new InputSource(sr);DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder=factory.newDocumentBuilder();Document doc = builder.parse(is);//XML转字符串TransformerFactory tf = TransformerFactory.newInstance();Transformer t = tf.newTransformer();t.setOutputProperty("encoding","utf-8");ByteArrayOutputStream bos = new ByteArrayOutputStream();t.transform(new DOMSource(doc), new StreamResult(bos));String xmlStr = bos.toString();