gpt4 book ai didi

xml - 在 GWT 客户端创建 XML 文档

转载 作者:数据小太阳 更新时间:2023-10-29 02:16:15 27 4
gpt4 key购买 nike

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

手动执行此操作是可能的,但非常不灵活,而且我看到自己犯了很多错误。所以我在 GWT 中寻找 XML 生成器并找到了“com.google.gwt.xml.client”包。遗憾的是我找不到如何用它创建 XML 文档的示例。谁能给我一个例子(或链接到一个例子)?

最好的问候,斯特凡

最佳答案

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

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

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

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());
}

关于xml - 在 GWT 客户端创建 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6895322/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com