PDA

View Full Version : Writing XML document to a file in GWT



Nishanth
28 Jul 2009, 11:26 PM
From the panel i have retrieved all the values and framed it into an XML document thro XMLParser and Document.
Now I need to write/save that as an .xml file
I tried with the Transformer(its not working)
and i tried by opening a file and writing thro Buffered reader.....
[Errors in 'file:/D:/eclipse/workspace/XMLProject/src/textToXMLPackage/client/TextToXML.java'
Line 59: No source code is available for type java.io.BufferedWriter; did you forget to inherit a required module?
Line 59: No source code is available for type java.io.FileWriter; did you forget to inherit a required module?
Line 62: No source code is available for type java.io.IOException; did you forget to inherit a required module?
]

Give an idea.. how to write the XMLdocument to the file.

jadrake75
29 Jul 2009, 2:55 PM
Your trying to do this in GWT? Or the server-side code called from GWT? GWT (and GXT) is a client-side library and uses the reduced Java API set from GWT. The only APIs supported are here: http://code.google.com/webtoolkit/doc/1.6/RefJreEmulation.html

There is only rudimentary output support for java.io

So to do this, you'd have to have the "server" perform your xml output... the general pattern would be to either make a web request or RPC call to the server, it creates your XML and provides it either a stream back (or provides a link to the temporarily location it is stored) - I believe to do this in a web container you need to grant some access privileges in the server config.... (shooting from the hip here)

Nishanth
29 Jul 2009, 11:46 PM
I am trying to create the XML document on the server side in GWT....

Arno.Nyhm
5 Aug 2009, 1:47 AM
but the error message and your path to your java class shows you try it on client side.

dea
30 Dec 2010, 8:15 AM
Hi,
I'm new on GWT...

someone has the patience to help me? I do not know how to write a DOM to an XML file using GWT

Thank you very much

Dea

sven
30 Dec 2010, 8:24 AM
Hi,
I'm new on GWT...

someone has the patience to help me? I do not know how to write a DOM to an XML file using GWT

Thank you very much

Dea

Can you please explain in detail what you want to do?

dea
30 Dec 2010, 8:34 AM
sven thanks for your response,

I have to write the values obtained as a parameter (via the widget in the panels) in an XML document. With GWT I can not use the library with classes javax DomSource and transformed ... I do not know how: (

If you give me a hand I will be liable!

Thanks

sven
30 Dec 2010, 8:36 AM
So you want to create a XML document? You should send the data to your server and create the file there, because you can use all the classes on the serverside.

dea
30 Dec 2010, 8:47 AM
Not only do I want to create a XML document but also manipulate it (add nodes, etc. ..)
Can you help me? First of all I have to create interfaces synchronous and asynchronous client-side right?

I'm very newbie: (

sven
30 Dec 2010, 8:48 AM
You can also manipulate it on your serverside. Simple send the informations to the server, for example with GWT RPC and do the changed to your xml file there. You need to use the serverside because of the classes you want to use.

dea
30 Dec 2010, 9:01 AM
At the moment in client-side I can read from an XML file but I can not write (I use the GWT class XMLParser ..). I can build my DOM tree.

How do I send values (taken from textbox) to the server? I then read them again and build the DOM tree (and especially write to files?)


Sorry but I've never used GWT RPC :-(

Thanks for your patience

sven
30 Dec 2010, 9:07 AM
When you use XmlParser and so on the client side, than also take a look at the other method the xml package from GWT offers you. There are also ways to manipulate the xml document

dea
30 Dec 2010, 9:12 AM
Yes, but to write to a file I'm forced to work in server-side right? What other methods? Because I did not find them..
Sorry if I insist ..

sven
30 Dec 2010, 9:14 AM
Yes, but to write to a file I'm forced to work in server-side right?
If you want to have it on a file, than yes, you always have to go to the serverside.

But if you do the modifications all on the clientside, than you can send the document as string to the server and simple return it as file download.

dea
30 Dec 2010, 9:20 AM
mmm ... I must also be able to add nodes to a tree. From what I understand I can create the new client-side structure, convert the entire property to a string and sends it to the server. Then in server-side I can write it to file as an XML document?
Do not know a tutorial where you can learn to do this, or if you have patience to explain the basics ..

Thank you very much

dea
30 Dec 2010, 9:26 AM
For example, this is my code, with this I build my XML structure that should be written to a file ..



":


final String nickname=textNickReg.getText();
final String pass=textPassReg.getText();
final String email2=textMail.getText();
final String gio=valueListBoxGG.getValue().toString();
final String mes=valueListBoxMM.getValue().toString();
final String ann=valueListBoxAA.getValue().toString();

RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
try{
Request response = builder.sendRequest(url, new RequestCallback() {
public void onError(Request request,
Throwable exception) {
Window.alert("errore nel sistema");
}
public void onResponseReceived(Request request,
Response response) {


Document xmlDoc = XMLParser.parse(response.getText());

Element root = xmlDoc.getDocumentElement(); //root=<utenti>


Element utente = xmlDoc.createElement("utente");

root.appendChild(utente);


Element nick = xmlDoc.createElement("nick");
Text nickTest = xmlDoc.createTextNode(nickname);

nick.appendChild(nickTest);

utente.appendChild(nick);

Element password = xmlDoc.createElement("psw");
Text pswTest = xmlDoc.createTextNode(pass);

password.appendChild(pswTest);

utente.appendChild(password);


Element email = xmlDoc.createElement("mail");
Text mailTest = xmlDoc.createTextNode(email2);

email.appendChild(mailTest);

utente.appendChild(email);


Element datan = xmlDoc.createElement("datan");

utente.appendChild(datan);

Element giorni = xmlDoc.createElement("gg");
Text ggTest = xmlDoc.createTextNode(gio);

giorni.appendChild(ggTest);

datan.appendChild(giorni);


Element mesi = xmlDoc.createElement("mm");
Text mmTest = xmlDoc.createTextNode(mes);

mesi.appendChild(mmTest);

datan.appendChild(mesi);


Element anni = xmlDoc.createElement("aa");
Text aaTest = xmlDoc.createTextNode(ann);

anni.appendChild(aaTest);

datan.appendChild(anni);