سؤال

I have an XML file in the res/xml folder which I want to parse using getXML().

But I also want to validate it first against an XSD schema.

How can I create a InputStreamReader for the XML file for validation?
It turns out that to use openRawResource() the file should be under res/raw or in assets

هل كانت مفيدة؟

المحلول

read it from the classpath, getclass -> getresourceasstream. For validation consider using the xerces lib.

نصائح أخرى

Put it under \res\xml\ folder. Then you can open it with:

 Resources res = activity.getResources();
 XmlResourceParser xrp = res.getXml(R.xml.your_resId);

Please follow below link for XMLResourceParser

http://android-er.blogspot.com/2010/04/read-xml-resources-in-android-using.html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top