Problem creating xml

4 views
Skip to first unread message

TiMIBoY Muff

unread,
Feb 4, 2020, 4:51:27 AM2/4/20
to CodenameOne Discussions
Hi there

I am trying to create a simple xml document.

I have never found a good documentation about it, so I just try it like this:

Element response = new Element("Artikelliste");
Element artikel1 = new Element("Artikel");
Element artikel2 = new Element("Artikel");
artikel1.setAttribute("nummer", "5678");
artikel1.setAttribute("bezeichnung", "KettenhandschuhXML");
artikel2.setAttribute("nummer", "1011");
artikel2.setAttribute("bezeichnung", "MesserXML");

response.addChild(artikel1);
response.addChild(artikel2);

OutputStream os = Storage.getInstance().createOutputStream("test1234.xml");
OutputStreamWriter writer = new OutputStreamWriter(os);
XMLWriter xmlWriter = new XMLWriter(false);
xmlWriter.writeXML(writer, response);

FileSystemStorage.getInstance().openOutputStream("test1234.xml").write(response.toString().getBytes());



I'm currently getting an IllegalArgumentException because of the last line, which says: test1234.xml is not a valid path, use FileSystemStorage.getInstance().getAppHomePath() to get a valid dir path to read / write files If I correct the corresponding line it looks like this:
FileSystemStorage.getInstance().openOutputStream(FileSystemStorage.getInstance().getAppHomePath()).write(response.toString().getBytes());

But the program cannot know which document is meant??! When I run the code like this, there is no error message and nothing happens...

Thanks for help! :)

Shai Almog

unread,
Feb 4, 2020, 9:08:54 PM2/4/20
to CodenameOne Discussions
Reply all
Reply to author
Forward
0 new messages