2012-01-04 2 views
0

SAXParser에 XML 페이지를 변수로 전달하는 데 문제가 있습니다. 아래 코드는 URL을 가져 와서 SAXParser에 전달하려고 시도하지만 오류가 발생합니다.SAXParser XML에 http url 전달

그러나 URL을 명시 적으로 정의하면 (변수를 사용하는 것이 아니라) 작동하면 좋습니다. 아무도 왜 이것이 실패하지 않습니다.

도움을 주실 수있는 분들께 감사드립니다. 나는 목적을보기 위해 코드를 잘라 냈다.

public class Parser extends DefaultHandler 
    private String link; 

    public void parseDocument() { 

     SAXParserFactory spf = SAXParserFactory.newInstance(); 
     try { 

      SAXParser sp = spf.newSAXParser(); 

      link = coll.getGcollId(id); // this successfully gets a string (url) to link to xml page over http string   
      //parse the file and also register this class for call backs 
      sp.parse(link, this); // when I run this code this line gets a "java.io.FileNotFoundException: http://foo.com/foo.xml" 
+0

이 http://foo.com/foo.xml가 올바른지되어 사용? – kosa

+0

아니요 코드를 모두 줄이려고했습니다. 오류의 출력은 올바른 URL입니다. – chuck

답변

3

는 대신 다음

SAXParserFactory spf = SAXParserFactory.newInstance(); 
SAXParser sp = spf.newSAXParser(); 
String link = coll.getGcollId(id); 
URL linkURL = new URL(link); 

sp.parse(new InputSource(url.openStream())); 
+0

고마워,하지만 똑같은 오류가 난다. – chuck

+0

내 원래 코드가 작동하는 것으로 나타났습니다. 내 XML 링크에 문자 오타가있었습니다. 도와 주셔서 정말로 고맙습니다. – chuck