手艺人赵鹏

  • 首页
  • 技术
  • 随笔
  • 归档
  • 友情链接

xml和字符串的转换

  • zhaopeng
  • 2009-07-06
  • 0
// 字符串转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();
© 2023 手艺人赵鹏
Theme by Wing
  • {{ item.name }}
  • {{ item.name }}