Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
New Developer
Posts: 18
Registered: ‎09-03-2008
My Device: Not Specified

Saving XML to file in 4.5.0

Hello,

 

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?

 

Thanks!

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Saving XML to file in 4.5.0

most parsers handle streams directly. if you want it as a String or something you can handle it as every other stream.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
New Developer
Posts: 18
Registered: ‎09-03-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

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?

New Developer
New Developer
Posts: 18
Registered: ‎09-03-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

Well... is it impossible to save XML to a file?
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

[ Edited ]

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.

 

Message Edited by BBDeveloper on 28-04-2009 01:59 PM

Use Search. "Accept Solution" If the problem is resolved.
New Developer
New Developer
Posts: 18
Registered: ‎09-03-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

The problem is that I can't find a method (in JDE 4.5) that would return XML contents.
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

You mean you have a complete xml file and you want to parse the data and save only the parsed data?

Use Search. "Accept Solution" If the problem is resolved.
New Developer
New Developer
Posts: 18
Registered: ‎09-03-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

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.

New Developer
New Developer
Posts: 18
Registered: ‎09-03-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

Ah, of course, by saying "to save XML" I mean saving org.w3c.dom.Document (or some alternative Document, if exists).
Developer
Developer
Posts: 319
Registered: ‎07-20-2008
My Device: Not Specified

Re: Saving XML to file in 4.5.0

Look at net.rim.device.api.xml.jaxp.XMLWriter