04-27-2009 11:12 AM
How can I save an XML to a file? The xml is prepared as follows:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element root = doc.createElement("Configuration"); doc.appendChild(root); Element elem = doc.createElement("element1"); root.appendChild(elem); // etc. // now save it to file: FileConnection file = (FileConnection)Connector.open(name_); if (!file.exists()) file.create(); else file.truncate(0); DataOutputStream out = file.openDataOutputStream(); out.write(doc.???);
In JDE 4.6 there's getTextContent() method. But how to take xml contents in 4.5?
04-27-2009 11:31 AM
04-27-2009 11:38 AM
I'm not sure I got the point... What I want is to save an XML (then to load it back). I can load it directly from a stream:
FileConnection file = (FileConnection)Connector.open(name_); DataInputStream in = file.openDataInputStream(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(in);
But how can I save xml to file?
04-28-2009 04:03 AM - edited 04-28-2009 04:29 AM
What problem you facing when you trying to save xml file to device using file connection?You can create a xml file and write the xml data to that file.
04-28-2009 04:43 AM
No, I mean I want to store/save the XML as-is. Later, I'd like to load it from the file, for instance, into org.w3c.dom.Document.
I know how to load xml from a file (see the code above), but I don't realize how to save XML - without walking though all its nodes/attributes manually.