怎么样把xml Document对象转换成字符串
2007-12-04 08:28
309 查看
public String doc2String(Document doc) {
String str = null;
try{
TransformerFactory factory = TransformerFactory.newInstance();
Transformer trans = factory.newTransformer();
trans.setOutputProperty(OutputKeys.ENCODING, "gb2312"); // 处理汉字编码
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
StreamResult strOut = new StreamResult(byteOut);
Source xmlSource = new DOMSource(doc);
trans.transform(xmlSource, strOut);
str = strOut.toString();
}catch(Exception e){
e.printStackTrace();
}
return str;
}
String str = null;
try{
TransformerFactory factory = TransformerFactory.newInstance();
Transformer trans = factory.newTransformer();
trans.setOutputProperty(OutputKeys.ENCODING, "gb2312"); // 处理汉字编码
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
StreamResult strOut = new StreamResult(byteOut);
Source xmlSource = new DOMSource(doc);
trans.transform(xmlSource, strOut);
str = strOut.toString();
}catch(Exception e){
e.printStackTrace();
}
return str;
}
相关文章推荐
- XML字符串转换成XML Document对象,并生成在指定路径
- C#对象转换为XML字符串和将Xml字符串转换为C#对象
- 关于XML字符串和XML Document之间的转换
- js字符串转换成xml对象并使用技巧解读
- 关于XML字符串和XML Document之间的转换
- 序列化之对象,字符串,byte数组,XML之间的转换(一)
- 把一个XML字符串转换为一个XML文档对象
- Java将org.w3c.dom.Element对象转换成xml字符串并且不带命名空间
- java XML字符串和XML DOCUMENT的相互转换
- 将字符串格式的XML转换成Dataset/XmlDocument
- javascript将字符串类型转换为XML对象
- 关于XML字符串和XML Document之间的转换
- 把list对象转换成xml字符串
- 对象和XML,JSON格式字符串的相互转换
- xml字符串转换为json对象
- js解析xml字符串或xml文件,将其转换为xml对象方法
- 关于XML字符串和XML Document之间的转换
- 将Xml字符串转换成(DataTable || DataSet)对象 !同样取反转换XML
- Xml字符串与C#对象之间相互转换
- 将Xml字符串转换成(DataTable || DataSet || XML)对象