안녕하세요.
xml parser 관련해서 질문 올립니다.
먼저 http호출한후 받아온 값을 xmlValues에 담아서 아래 domParse을 호출합니다.
factory.setValidating(true);가 없을때는 정상적으로 동작합니다.
문제는 factory.setValidating(true);를 추가하면 parser = factory.newDocumentBuilder();에서 익셉션이 발생한다는 겁니다.
뭐가 문제인지 회원님들의 한말씀 기다립니다.
public void domParse(){
try {
pd.dismiss();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
DocumentBuilder parser;
parser = factory.newDocumentBuilder();
Document root = parser.parse(new InputSource(new StringReader(xmlValues)));
Node codeNode = root.getElementsByTagName("resultCode").item(0);
String codeValue = codeNode.getFirstChild().getNodeValue();
Node msgNode = root.getElementsByTagName("resultMsg").item(0);
String msgValue = msgNode.getFirstChild().getNodeValue();
if(codeValue.equals("000")) {
mopasApp.saveCheckPreferences(false);
Log.d("min_test", "message : " + msgValue);
mopasApp.saveAuthPreferences(true);
mopasApp.saveAuthCodePreferences(mbAuthCode);
exHandler.sendEmptyMessage(2);
}else {
Log.d("min_test", "error message : " + msgValue);
exHandler.sendEmptyMessage(1);
}
} catch (ParserConfigurationException e) {
System.out.println(e);
exHandler.sendEmptyMessage(2);
} catch (SAXException e) {
System.out.println(e);
exHandler.sendEmptyMessage(2);
} catch (IOException e) {
System.out.println(e);
exHandler.sendEmptyMessage(2);
}
}




api reference를 보면 답이 나옵니다만 간략히 말씀드리자면
DocumentBuilderFactory.setValidating(boolean validating)은
xml문서를 dtd검증 하겠다는 의미입니다.
xml 문서 상위쪽에 dtd를 정의하면 아마 자동으로 인식할 것 같긴합니다만
저 같은 경우는 dtd를 만들어 브라우저상에 적용까진 해보았는데
DocumentBuilderFactory.setValidating(booelan) 메소드를 써본적이 없습니다.
api를 보니 비공식적인 방법으로
setSchema(Schema)로도 검증을 할 수 있다고 되어 있습니다.자세한 내용은 구글링 해보시면 많이 나올 듯 합니다.