Reputation: 3257
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...
Upvotes: 0
Views: 1497
Reputation: 6715
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
Upvotes: 0
Reputation: 1006614
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.
Upvotes: 1