在GWT客户端创建XML文档 [英] Create XML document on GWT client side

查看:124
本文介绍了在GWT客户端创建XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在客户端上创建一些XML文件,然后将它们发送到服务器(没有什么特别的,就像< root>< blabla> ...< / blabla> ; ...< / root> )。

I'm trying to create some XML files on the client and then send them to the server (nothing special, just something like <root><blabla>...</blabla>...</root>).

手动操作可能会非常不灵活,而且我看到自己做了很多的错误。所以我在GWT中寻找一个XML生成器,并找到了com.google.gwt.xml.client包。可悲的是我无法找到如何使用它创建XML文档的示例。有人可以给我一个例子吗?

Doing this by hand would be possible but extremely inflexible and I see myself making a lot of mistakes. So I was looking for a XML generator in GWT and found the "com.google.gwt.xml.client" Package. Sadly I cant find examples how to create XML documents with it. Can anybody provide me an example (or linke ot an examle)?

最好的问候,
Stefan

Best regards, Stefan

推荐答案

这里是一个例子。要生成以下xml:

Here is an example. To generate the following xml :

<root>
  <node1 attribute="test">
     my value
  </node1>
  <node2 attribute="anothertest"/>
</root>

您必须在Java客户端编写以下代码:

You have to write the following code on the Java client side :

import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.XMLParser;

public static void main(String[] args) {
    Document doc = XMLParser.createDocument();

    Element root = doc.createElement("root");
    doc.appendChild(root);

    Element node1 = doc.createElement("node1");
    node1.setAttribute("attribute","test");
    node1.appendChild(doc.createTextNode("my value"));
    doc.appendChild(node1);

    Element node2 = doc.createElement("node2");
    node2.setAttribute("attribute","anothertest");
    doc.appendChild(node2);

    System.out.println(doc.toString());
}

这篇关于在GWT客户端创建XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆