String modelXML = convertXMLFileToString("/Temp/source_backup/" +prdModels[i].trim()+ ".xml");
/** XML to String **/
public String convertXMLFileToString(String fileName)
{
try
{
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
InputStream inputStream = new FileInputStream(new File(fileName));
org.w3c.dom.Document doc = documentBuilderFactory.newDocumentBuilder().parse(inputStream);
StringWriter stw = new StringWriter();
Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.transform(new DOMSource(doc), new StreamResult(stw));
return stw.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return "";
}
/** XML to String **/
public String convertXMLFileToString(String fileName)
{
try
{
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
InputStream inputStream = new FileInputStream(new File(fileName));
org.w3c.dom.Document doc = documentBuilderFactory.newDocumentBuilder().parse(inputStream);
StringWriter stw = new StringWriter();
Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.transform(new DOMSource(doc), new StreamResult(stw));
return stw.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return "";
}
'Dev > java, flex, jsp, js' 카테고리의 다른 글
Charset and Codepage (310) | 2009.06.26 |
---|---|
[Java] String Encoding (1) | 2009.06.25 |
[펌] Ant를 알아보자... (0) | 2009.04.09 |
[펌]According to TLD or attribute directive in tag file, attribute test does not accept any expressions (218) | 2009.02.02 |
jstl redirect with parameter (0) | 2008.12.16 |