g
public static Document getNewDoc(String xmlStr)
{
Document doc = null;
try
{
StringReader sr = new StringReader(xmlStr);
InputSource iSrc = new InputSource(sr);
DocumentBuilder builder=getBuilder();
doc = builder.parse(iSrc);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return doc;
}
//save a document as a file at the given file path
public static void save(Document doc, String filePath)
{
try
{
OutputFormat format = new OutputFormat(doc); //Serialize DOM
format.setEncoding("GB2312");
StringWriter stringOut = new StringWriter(); //Writer will be a String
XMLSerializer serial = new XMLSerializer(stringOut, format);
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize(doc.getDocumentElement());
String STRXML = stringOut.toString(); //Spit out DOM as a String
String path = filePath;
writeXml(STRXML, path);
}
catch (Exception e)
{
&nb
public static Document getNewDoc(String xmlStr)
{
Document doc = null;
try
{
StringReader sr = new StringReader(xmlStr);
InputSource iSrc = new InputSource(sr);
DocumentBuilder builder=getBuilder();
doc = builder.parse(iSrc);
}
catch (Exception ex)
{
ex.printStackTrace();
}
return doc;
}
//save a document as a file at the given file path
public static void save(Document doc, String filePath)
{
try
{
OutputFormat format = new OutputFormat(doc); //Serialize DOM
format.setEncoding("GB2312");
StringWriter stringOut = new StringWriter(); //Writer will be a String
XMLSerializer serial = new XMLSerializer(stringOut, format);
serial.asDOMSerializer(); // As a DOM Serializer
serial.serialize(doc.getDocumentElement());
String STRXML = stringOut.toString(); //Spit out DOM as a String
String path = filePath;
writeXml(STRXML, path);
}
catch (Exception e)
{
&nb
| 对此文章发表了评论 |
