Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在客户端使用GWT构建RSS_Java_Xml_Gwt - Fatal编程技术网

Java 在客户端使用GWT构建RSS

Java 在客户端使用GWT构建RSS,java,xml,gwt,Java,Xml,Gwt,我使用com.google.gwt.xml.client.* 我需要在XML的开头和项目块内部创建标题元素。但是,当我选择createElement(“标题”)和appendChild(标题)时,最后只得到一个元素标题 private void formXMLToSend(){ Document doc = XMLParser.createDocument(); Element root = doc.createElement("rss"); root.setAttribute("v

我使用com.google.gwt.xml.client.*

我需要在XML的开头和项目块内部创建标题元素。但是,当我选择createElement(“标题”)和appendChild(标题)时,最后只得到一个元素标题

private void formXMLToSend(){
  Document doc = XMLParser.createDocument();
  Element root = doc.createElement("rss");
  root.setAttribute("version", "2.0");
  doc.appendChild(root);

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

  Element title = doc.createElement("title");
  title.appendChild(doc.createTextNode("sitename"));
  Element link = doc.createElement("link");
  link.appendChild(doc.createTextNode("http://mysite.com"));

  chl.appendChild(title);
  chl.appendChild(link);

  for(int i = 0; i < items.size(); i++){
    Element item = doc.createElement("item");
    Element subTitle = doc.createElement("title");
    title.appendChild(doc.createTextNode(items.get(i).getName()));
    Element descr = doc.createElement("description");
    descr.appendChild(doc.createTextNode(items.get(i).getText()));
    item.appendChild(title);
    item.appendChild(descr);
    chl.appendChild(item,link);
  }

  Window.alert(doc.toString());
}
private void formXMLToSend(){
Document doc=XMLParser.createDocument();
元素根=doc.createElement(“rss”);
setAttribute(“版本”,“2.0”);
doc.appendChild(根);
元素chl=doc.createElement(“通道”);
根附属物(chl);
元素标题=doc.createElement(“标题”);
title.appendChild(doc.createTextNode(“sitename”);
元素链接=doc.createElement(“链接”);
link.appendChild(doc.createTextNode(“http://mysite.com"));
儿童(头衔);
附属儿童(链接);
对于(int i=0;i
公共字符串createRss2(列表项){
Document doc=(Document)XMLParser.createDocument();
元素根=doc.createElement(“rss”);
setAttribute(“版本”,“2.0”);
doc.appendChild(根);
元素chl=doc.createElement(“通道”);
根附属物(chl);
元素标题=doc.createElement(“提要标题”);
title.appendChild(doc.createTextNode(“sitename”);
儿童(头衔);
元素链接=doc.createElement(“链接”);
link.appendChild(doc.createTextNode(“http://mysite.com"));
附属儿童(链接);
元素描述=doc.createElement(“描述”);
description.appendChild(doc.createTextNode(“某些说明”);
儿童(描述);
元素lang=doc.createElement(“语言”);
lang.appendChild(doc.createTextNode(“en”);
儿童(朗);
元素版权=doc.createElement(“版权”);
appendChild(doc.createTextNode(“nicolas schwarzentrub”))版权所有;
儿童(版权所有);
元素pubDate=doc.createElement(“pubDate”);
appendChild(doc.createTextNode(DateTimeFormat.getFormat(“EEE,dd-MMM-yyyy-hh:mm:ss-ZZZZ”).format(new-Date()));
儿童(pubDate);
元素图像=doc.createElement(“图像”);
Element imageUrl=doc.createElement(“url”);
imageUrl.appendChild(doc.createTextNode(“https://ssl.gstatic.com/gb/images/j_e6a6aca6.png"));
元素imageTitle=doc.createElement(“标题”);
appendChild(doc.createTextNode(“图像的某些标题”);
元素imageLink=doc.createElement(“链接”);
imageLink.appendChild(doc.createTextNode(“http://www.google.ch/"));
appendChild(imageUrl);
image.appendChild(imageTitle);
appendChild(imageLink);
儿童(图片);
对于(项目obj:项目)
{
元素项=doc.createElement(“项目”);
元素itemTitle=doc.createElement(“标题”);
appendChild(doc.createTextNode(obj.getName());
item.appendChild(itemTitle);
元素itemDescription=doc.createElement(“描述”);
appendChild(doc.createTextNode(obj.getText());
item.appendChild(itemDescription);
Element itemLink=doc.createElement(“链接”);
appendChild(doc.createTextNode(obj.getLink());
item.appendChild(itemLink);
元素itemAuthor=doc.createElement(“作者”);
appendChild(doc.createTextNode(obj.getAuthor());
item.appendChild(itemAuthor);
//如果需要的话,还有其他的。。
元素itemPubDate=doc.createElement(“pubDate”);
itemPubDate.appendChild(doc.createTextNode(DateTimeFormat.getFormat(“EEE,dd-MMM-yyyy-hh:mm:ss-ZZZZ”).format(new-Date());
item.appendChild(itemPubDate);
//将此项附加到link元素
附肢儿童(项目);
}
返回doc.toString();
}
要测试它,请将以下内容放入GWTTestCase中

    List<Item> theItems = new ArrayList<TestXML.Item>();
    for(int i= 0; i<3 ; i++)
    {
    theItems.add(new Item("item "+i, "description of item "+i, "n.s","http://www.stackoverflow.com"));
    }

    System.out.println( createRss2(theItems));
List=newarraylist();

例如,对于(inti=0;iThanks),我确实在代码中的变量名中发现了bug。
    List<Item> theItems = new ArrayList<TestXML.Item>();
    for(int i= 0; i<3 ; i++)
    {
    theItems.add(new Item("item "+i, "description of item "+i, "n.s","http://www.stackoverflow.com"));
    }

    System.out.println( createRss2(theItems));
<rss version="2.0">
<channel>
    <title of the feed>sitename</title of the feed>
    <link>http://mysite.com</link>
    <description>some description</description>
    <language>en</language>
    <copyright>nicolas schwarzentrub</copyright>
    <pubDate>Wed, 05 Sep 2012 02:15:07 GMT+02:00</pubDate>
    <image>
        <url>https://ssl.gstatic.com/gb/images/j_e6a6aca6.png</url>
        <title>some title of image</title>
        <link>http://www.google.ch/</link>
    </image>
    <item>
        <title>item 0</title>
        <description>description of item 0</description>
        <link>http://www.stackoverflow.comn.s</link>
        <author />
        <pubDate>Wed, 05 Sep 2012 02:15:07 GMT+02:00</pubDate>
    </item>
    <item>
        <title>item 1</title>
        <description>description of item 1</description>
        <link>http://www.stackoverflow.comn.s</link>
        <author />
        <pubDate>Wed, 05 Sep 2012 02:15:07 GMT+02:00</pubDate>
    </item>
    <item>
        <title>item 2</title>
        <description>description of item 2</description>
        <link>http://www.stackoverflow.comn.s</link>
        <author />
        <pubDate>Wed, 05 Sep 2012 02:15:07 GMT+02:00</pubDate>
    </item>
</channel>