Question

How would I go about reading XML from a file on the device? Can you add the XML to a .res file? I know the XML parser expects a reader, but can you use a reader to read out the .res file?

Regards,

Dylan

Was it helpful?

Solution

Yes, you absolutely can. Open the theme.res file with the Codename One Designer and add your xml file from the Data section on the left. Now you can load the file using the theme object as follows:

InputStream is = theme.getData("yourFile.xml");

Alternatively, You can put your xml in the class path (e.g. java source directory) and load it as follows:

InputStream is = Display.getInstance().getResourceAsStream(null, "/yourFile.xml");

Once you got an InputStream, simply wrap it with a Reader

XMLParser xmlParser = new XMLParser();
xmlParser.parse(new InputStreamReader(is, "UTF-8"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top