2012-12-05 5 views
0

res/values에서 문자열로 파일 이름을 참조하여 에셋에있는 xml 파일을 구문 분석 할 수 있습니까?문자열로 참조되는 Android parse xml

Document doc = db.parse(assetManager.open("questions.xml")); 

및 questions.xml 대신 @ string/questions.xml이 필요합니까? 이 문제를 해결하는 데 어려움을 겪고 있습니다.

+0

[XML 데이터 구문 분석] (http://developer.android.com/training/basics/network-ops/xml.html) – chridam

+0

왜 그럴 수 있습니까? 질문 목록이 있으면 사용하십시오. http://developer.android.com/guide/topics/resources/string-resource.html#StringArray – Ascension

+0

정말 가능한지 알고 싶습니다. – WiseGuy

답변

2

당신이 코드로 작업을 수행 할 수 있습니다

Document doc = db.parse(assetManager.open(getApplicationContext().getResources().getString(R.string.questions)); 

희망하는 데 도움이 :

Resources res = getApplicationContext().getResources(); 
String filename = res.getString(R.string.questions); 
Document doc = db.parse(assetManager.open(filename)); 

또는 하나 개의 간단한 라인

.

+0

Arcastro 예 감사합니다 이것은 정확하게 내가 뭘했는지, 유일한 것은 getApplicationContext 오류가 한 줄 예제를 통해 메서드를 확인할 수 없다는 것입니다. – WiseGuy

+0

작업 내에서 메서드를 호출하지 않을 경우, getResources()를 호출하려면 현재 Context를 매개 변수로 전달해야합니다. –

+0

대단히 감사합니다. – WiseGuy