sp; e.printStackTrace();
}
}
//save a string(xml) in the given file path
public static void writeXml(String STRXML, String path)
{
try
{
File f = new File(path);
PrintWriter out = new PrintWriter(new FileWriter(f));
out.print(STRXML + "\n");
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
//format a document to string
public static String toString(Document doc)
{
String STRXML = null;
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());
STRXML = stringOut.toString(); //Spit out DOM as a String
}
catch (Exception e)
{
e.printStackTrace();
}
&
}
}
//save a string(xml) in the given file path
public static void writeXml(String STRXML, String path)
{
try
{
File f = new File(path);
PrintWriter out = new PrintWriter(new FileWriter(f));
out.print(STRXML + "\n");
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
//format a document to string
public static String toString(Document doc)
{
String STRXML = null;
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());
STRXML = stringOut.toString(); //Spit out DOM as a String
}
catch (Exception e)
{
e.printStackTrace();
}
&
| 对此文章发表了评论 |
