Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8481957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:42:02+00:00 2026-06-10T19:42:02+00:00

I use com.google.gwt.xml.client.*. I need to create title elements in the beginning of XML

  • 0

I use com.google.gwt.xml.client.*.

I need to create title elements in the beginning of XML and inside the item blocks. But when I select createElement(“title”) and appendChild(title), I get only one Element title in the end.

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());
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:42:04+00:00Added an answer on June 10, 2026 at 7:42 pm
    public  String createRss2(List<Item> items){
        Document doc = (Document) 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 of the feed");
        title.appendChild(doc.createTextNode("sitename"));
        chl.appendChild(title);
    
        Element link = doc.createElement("link");
        link.appendChild(doc.createTextNode("http://mysite.com"));
        chl.appendChild(link);
    
        Element description = doc.createElement("description");
        description.appendChild(doc.createTextNode("some description"));
        chl.appendChild(description);
    
        Element lang = doc.createElement("language");
        lang.appendChild(doc.createTextNode("en"));
        chl.appendChild(lang);
    
        Element copyright = doc.createElement("copyright");
        copyright.appendChild(doc.createTextNode("nicolas schwarzentrub"));
        chl.appendChild(copyright);
    
        Element pubDate = doc.createElement("pubDate");
        pubDate.appendChild(doc.createTextNode(DateTimeFormat.getFormat("EEE, dd MMM yyyy hh:mm:ss ZZZZ").format(new Date())));
        chl.appendChild(pubDate);
    
    
        Element image = doc.createElement("image");
        Element imageUrl = doc.createElement("url");
        imageUrl.appendChild(doc.createTextNode("https://ssl.gstatic.com/gb/images/j_e6a6aca6.png"));
        Element imageTitle = doc.createElement("title");
        imageTitle.appendChild(doc.createTextNode("some title of image"));
        Element imageLink = doc.createElement("link");
        imageLink.appendChild(doc.createTextNode("http://www.google.ch/"));
    
        image.appendChild(imageUrl);
        image.appendChild(imageTitle);
        image.appendChild(imageLink);
        chl.appendChild(image);
    
        for(Item obj : items)
        {
            Element item = doc.createElement("item");
    
            Element itemTitle = doc.createElement("title");
            itemTitle.appendChild(doc.createTextNode(obj.getName()));
            item.appendChild(itemTitle);
    
    
            Element itemDescription = doc.createElement("description");
            itemDescription.appendChild(doc.createTextNode(obj.getText()));
            item.appendChild(itemDescription);
    
            Element itemLink = doc.createElement("link");
            itemLink.appendChild(doc.createTextNode(obj.getLink()));
            item.appendChild(itemLink);
    
            Element itemAuthor = doc.createElement("author");
            itemLink.appendChild(doc.createTextNode(obj.getAuthor()));
            item.appendChild(itemAuthor);
            //and others if needed ..
            Element itemPubDate = doc.createElement("pubDate");
            itemPubDate.appendChild(doc.createTextNode(DateTimeFormat.getFormat("EEE, dd MMM yyyy hh:mm:ss ZZZZ").format(new Date())));
            item.appendChild(itemPubDate);
    
            //append this item to the link element
            chl.appendChild(item);
        }
    
    
       return doc.toString();
      }
    

    To test it, put the following in a 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));
    

    The following above code fragment will produce the xml below

    <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>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the gwt Geolocation-Package ( com.google.gwt.geolocation.client.Geolocation ) to read the current Location on
I am trying to use smart Gwt, Listgrid. I am using both com.google.gwt.user.client.ui and
I'm tring to use com.google.android.apps.analytics.GoogleAnalyticsTracker but got NoClassDefFoundError when GoogleAnalyticsTracker.getInstance(); I'm sure that libGoogleAnalytics.jar
I have a typical GWT app, in my module.xml, I have, <inherits name='com.google.gwt.user.theme.standard.Standard' />
I am trying to use : http://code.google.com/p/jspf/ within a GWT framework. I know that
I am trying to use GWT xml parser but the compiler throws next [ERROR]
I'm working with GWT and Google App Engine... I use com.google.gwt.core.ext.Generator to load dynamic
I wan't use several css files in one uibinder, like <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui'> <ui:style
I am trying to use http://code.google.com/p/as3svgrendererlib/ in my flash cs 5.5 project to import
I want to use oscpack ( http://code.google.com/p/oscpack/ ) as a static library for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.