0

I have an xml file(thexml.xml) and it's related dtd(thedtd.dtd) file in res/raw folder. this is the DOCTYPE of the xmlfile: <!DOCTYPE myApp SYSTEM "thedtd.dtd"> Because the address to the dtd file has been set relatively i get this error:

org.xml.sax.SAXParseException: Relative URI "thedtd.dtd"; 
can not be resolved without a base URI. 

So I am thinking to give the DOCTYPE an absolute path to the dtd file but i don't know what the address is. i tried this

android.resource://com.ssh.mine/raw/thedtd

note: (com.ssh.mine is the package name of my project)

but it didn't work and i got java.net.MalformedURLException. so what should the absolute path to the res/raw folder be...

Gandalf
  • 2,921
  • 5
  • 31
  • 44
  • 1
    there are not such thing like absolute path to the resources but you could see ContentResolver.openAssetFileDescriptor/openInputStream methods and how they work with ContentResolver.SCHEME_ANDROID_RESOURCE scheme – pskink Sep 01 '14 at 17:28

2 Answers2

1

what is the absolute path to the res/raw folder in your app?

There is no path. Raw resources are entries in a ZIP archive that is your APK.

I have an xml file(thexml.xml) and it's related dtd(thedtd.dtd) file in res/raw folder. this is the DOCTYPE of the xmlfile: Because the address to the dtd file has been set relatively i get this error:

You may have better luck using assets/ rather than res/raw/, though depending on what you are using to consume the XML, I suspect that neither will work. Worst-case scenario, you will need to copy the files to internal storage (e.g., getFilesDir()) and then use them.

Or, put the XML in res/xml/ and get rid of the DTD, in which case you can get an XmlPullParser on the XML from the Resources object.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Resources are a part of the APK file. There is no way to refer to a segment of the APK with a URI.

Instead, you should intercept your parser's call to locate the DTD. Presuming you are using the built-in Android parser, have a look at the docs for EntityResolver

G. Blake Meike
  • 6,615
  • 3
  • 24
  • 40