2013-07-19 4 views
0

내 응용 프로그램에서 DOM 파서를 사용하여 XML 파일을 구문 분석하려고합니다. 구문 분석이 성공하면 파일은 성공 디렉토리로 이동하고 다른 디렉토리는 오류 디렉토리로 이동합니다. 다음으로 파일이 소스 디렉토리에서 삭제됩니다.DOM 파서로 XML 구문 분석

문제는 XML 파일 (예 : Xml 문서 끝에 끝 태그가 없음) 예외 다음과 같은 오류 메시지가 표시됩니다.

"다른 프로세스에서 사용하고 있기 때문에 는 프로세스가 파일을 액세스 할 수 없습니다."

을 인해 파일이 소스 디렉토리에서 삭제되지 않습니다에. 난 그냥 simle 방법을 발견

+0

당신은 예외를 잡을 필요 캐치에 당신은 폴더를 오류 XML을 이동해야합니다. 문제의 코드를 업데이트하십시오. – vels4j

+0

언어 또는 특정 기술을 명시하지 않았으므로 우리가 할 수있는 것은 추측입니다. 예외적 인 경우에 무언가가 적시에 정리되지 않을 가능성이 있습니다. 예를 들어,'finally' 블록이나'using' 절을 적절하게 사용하면 언어가 지원하는 경우이를 수정할 수 있습니다. –

+0

안녕하세요 vels4j, 난 code.thanks –

답변

0

public class XMLLoader extends Thread { 
boolean success =false; 
public XMLLoader(SoapConnection con, String xmlPath) { 

    try { 
     System.out.println("Laoding the XML..."); 
     File file = new File(xmlPath); 
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     DocumentBuilder builder = factory.newDocumentBuilder(); 
     Document document = builder.parse(file); 
     String xmlString = null; 

     DOMSource domSource = new DOMSource(document); 
     StringWriter writer = new StringWriter(); 
     StreamResult result = new StreamResult(writer); 
     TransformerFactory tf = TransformerFactory.newInstance(); 
     Transformer transformer = tf.newTransformer(); 
     transformer.transform(domSource, result); 
     xmlString = writer.toString(); 
     InboundCaseXmlResponse cResponse = con.LoadXmlCase(xmlString); 
     System.out.println("SOAP Response == "+cResponse); 
     if(cResponse.getHasErrors()== false) 
     { 
      success = true; 
     } 


    } catch (Exception e) { 
     System.out.println(e.getMessage()); 

     } 


} 
public boolean getStatus() 
{ 
    return success; 
} 

} ..

private static boolean loadXml(SoapConnection con, String xmlPath) { 
    boolean success =false; 
    FileInputStream file=null; 
    try { 
     System.out.println("Loading the XML..."); 
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     DocumentBuilder builder = factory.newDocumentBuilder(); 
     file = new FileInputStream(xmlPath); 
     Document document = builder.parse(file); 
     System.out.println(document.hasChildNodes()); 
     String xmlString = null;    
     DOMSource domSource = new DOMSource(document); 
     StringWriter writer = new StringWriter(); 
     StreamResult result = new StreamResult(writer); 
     TransformerFactory tf = TransformerFactory.newInstance(); 
     Transformer transformer = tf.newTransformer(); 
     transformer.transform(domSource, result); 
     xmlString = writer.toString(); 
     InboundCaseXmlResponse cResponse = con.LoadXmlCase(xmlString); 
     System.out.println("SOAP Response == "+cResponse); 
     if(cResponse.getHasErrors()== false) 
     { 
      success = true; 
     } 
     } catch (Exception e) { 
     System.out.println(e.getMessage()); 
     try{ 
     file.close(); 
     } 
     catch(Exception ex) 
     { 
     e.printStackTrace();  
     } 

     } 

    return success; 
}