can atom be read as xml

hi all,

i know atom is xml. And i know they are slightly different.

My question is : instead of using xml, can i use atom and datasource.setdataurl(ATOM) and withdraw data from it ?

if it can be done, what should i put under setRecordPath(), refering to the below atom that i got from twitter. THANKS

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:google="http://base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/">
  <id>tag:search.twitter.com,2005:search/twitter</id>
  <link type="text/html" rel="alternate" href="http://search.twitter.com/search?q=twitter"/>
  <link type="application/atom+xml" rel="self" href="http://search.twitter.com/search.atom?q=twitter"/>
  <title>twitter - Twitter Search</title>
  <link type="application/opensearchdescription+xml" rel="search" href="http://search.twitter.com/opensearch.xml"/>
  <link type="application/atom+xml" rel="refresh" href="http://search.twitter.com/search.atom?q=twitter&since_id=1271847833"/>
  <updated>2009-03-03T01:36:35Z</updated>
  <openSearch:itemsPerPage>15</openSearch:itemsPerPage>
  <link type="application/atom+xml" rel="next" href="http://search.twitter.com/search.atom?max_id=1271847833&page=2&q=twitter"/>
  <entry>
    <id>tag:search.twitter.com,2005:1271847833</id>
    <published>2009-03-03T01:36:35Z</published>
    <link type="text/html" rel="alternate" href="http://twitter.com/andyvengence/statuses/1271847833"/>
    <title>I love how twitter gives you a "nah, nevermind. were cool" option when you block someone. Lmao...i got a kick out of that.</title>
    <content type="html">I love how <b>twitter</b> gives you a &quot;nah, nevermind. were cool&quot; option when you block someone. Lmao...i got a kick out of that.</content>
    <updated>2009-03-03T01:36:35Z</updated>
    <link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/85342200/m_542a51099b25ce411f855343eceb7df8_normal.jpg"/>
    <twitter:source><a href="http://help.twitter.com/index.php?pg=kb.page&id=75">txt</a></twitter:source>
    <author>
      <name>andyvengence (andrew choynowski)</name>
      <uri>http://twitter.com/andyvengence</uri>
    </author>
  </entry>
  <entry>
    <id>tag:search.twitter.com,2005:1271847788</id>
    <published>2009-03-03T01:36:34Z</published>
    <link type="text/html" rel="alternate" href="http://twitter.com/johnbdavis/statuses/1271847788"/>
    <title>Re: Gmail down. Gmail actually seems OK. But tonight, I had no luck accessing via Safari v4 (wtf?).  Thanks for the scoop twitter search.</title>
    <content type="html">Re: Gmail down. Gmail actually seems OK. But tonight, I had no luck accessing via Safari v4 (wtf?).  Thanks for the scoop <b>twitter</b> search.</content>
    <updated>2009-03-03T01:36:34Z</updated>
    <link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/66510964/John1_normal.jpg"/>
    <twitter:source><a href="http://www.tweetdeck.com/">TweetDeck</a></twitter:source>
    <author>
      <name>johnbdavis (John Davis)</name>
      <uri>http://twitter.com/johnbdavis</uri>
    </author>
  </entry>
  <entry>
    <id>tag:search.twitter.com,2005:1271847749</id>
    <published>2009-03-03T01:36:33Z</published>
    <link type="text/html" rel="alternate" href="http://twitter.com/mandyelric/statuses/1271847749"/>
    <title>arrumando meu twitter ;)</title>
    <content type="html">arrumando meu <b>twitter</b> ;)</content>
    <updated>2009-03-03T01:36:33Z</updated>
    <link type="image/png" rel="image" href="http://static.twitter.com/images/default_profile_normal.png"/>
    <twitter:source><a href="http://twitter.com/">web</a></twitter:source>
    <author>
      <name>mandyelric (Amanda Oliveira)</name>
      <uri>http://twitter.com/mandyelric</uri>
    </author>
  </entry>
  <entry>
    <id>tag:search.twitter.com,2005:1271847721</id>
    <published>2009-03-03T01:36:33Z</published>
    <link type="text/html" rel="alternate" href="http://twitter.com/paulcarr/statuses/1271847721"/>
    <title>@dotBen Also, as far as monitoring me is concerned, it's not exactly difficult, what with the column, blog, Twitter and soon another book.</title>
    <content type="html"><a href="http://twitter.com/dotBen">@dotBen</a> Also, as far as monitoring me is concerned, it's not exactly difficult, what with the column, blog, <b>Twitter</b> and soon another book.</content>
    <updated>2009-03-03T01:36:33Z</updated>
    <link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/53213320/2432746299_a6fc436a87_b_normal.jpg"/>
    <link type="application/atom+xml" rel="thread" href="http://search.twitter.com/search/thread/1271847721.atom"/>
    <twitter:source><a href="http://twitter.com/">web</a></twitter:source>
    <author>
      <name>paulcarr (paulcarr)</name>
      <uri>http://twitter.com/paulcarr</uri>
    </author>
  </entry>
</feed>

am i correct to use the below Xpath? because i can’t retrieve data from the atom!

setRecordXPath(“/feed/id/link/link/title/link/link/update/openSearch:itemsPerPage/link/entry”); referring to the atom pasted above!

i still couldn’t read the atom file.

below is my ATOMXmlDS which extends datasource.

can someone advice me ? i suspect the element attributes are giving the problem. how can i solve them ?

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceLinkField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.data.fields.DataSourceImageField;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;

public class ATOMXmlDS  extends DataSource{

	
	   private static ATOMXmlDS instance = null;

	    public static ATOMXmlDS getInstance() {
	        if (instance == null) {
	            instance = new ATOMXmlDS("ATOM2DS");
	        }
	        return instance;
	    }

	    public ATOMXmlDS(String id) {

	        setID(id);
	        setRecordXPath("/feed/entry");
	        DataSourceTextField idField = new DataSourceTextField("id", "ID");

	        setFields(idField);

	        setDataURL("ds/test_data/atom.data.xml");
	        setClientOnly(true);
	    }


}

Those elements you are trying to select are in specific XML namespaces and you haven’t put any namespaces in your XPath. XML namespaces are a big topic - try searching online for tutorials and references. Once you understand, look at the DataSource.xmlNamespaces API.

Help

thanks isomorphic.i checked out the xmlnamespace. i wanted to extract the following <twitter:source>

<twitter:source><a href="http://help.twitter.com/index.php?pg=kb.page&id=75">txt</a></twitter:source>

and i do the following code:

  XmlNamespaces xmlnamespace = new XmlNamespaces();
	        xmlnamespace.addNamespace("twitter", "http://api.twitter.com/");
	        setXmlNamespaces(xmlnamespace);

But it is still not extracted.can someone advise me what to do next?

and also, how can i extract the following:

<link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/85342200/m_542a51099b25ce411f855343eceb7df8_normal.jpg"/>

and the nested element “name” and “uri”

<author>
      <name>andyvengence (andrew choynowski)</name>
      <uri>http://twitter.com/andyvengence</uri>
    </author>

below is my full code for datasource

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.XmlNamespaces;
import com.smartgwt.client.data.fields.DataSourceFloatField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceLinkField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.data.fields.DataSourceImageField;
import com.smartgwt.client.types.DSDataFormat;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;

public class Twitter2XmlDS  extends DataSource{

	
	   private static Twitter2XmlDS instance = null;

	    public static Twitter2XmlDS getInstance() {
	        if (instance == null) {
	            instance = new Twitter2XmlDS("twitterDS");
	        }
	        return instance;
	    }

	    public Twitter2XmlDS(String id) {

	        setID(id);
	        setRecordXPath("//default:entry");
	        setDataURL("ds/test_data/twitter2.data.xml");
	        XmlNamespaces xmlnamespace = new XmlNamespaces();
	        xmlnamespace.addNamespace("twitter", "http://api.twitter.com/");
	        setXmlNamespaces(xmlnamespace);
	        
	        DataSourceTextField title_Field = new DataSourceTextField("title", "Title");
	        DataSourceTextField updated_Field = new DataSourceTextField("updated", "Updated");
	        DataSourceTextField published_Field = new DataSourceTextField("published", "Published");
	        DataSourceTextField id_Field = new DataSourceTextField("id", "Id");
	        DataSourceTextField twitter_source_Field = new DataSourceTextField("twitter:source", "twitter:source");
	        DataSourceTextField link_href_Field = new DataSourceTextField("href", "Href");
	        link_href_Field.setValueXPath("link/href");
	        DataSourceTextField uri_Field = new DataSourceTextField("uri", "uri");
	        link_href_Field.setValueXPath("author/uri");
	        DataSourceTextField name_Field = new DataSourceTextField("name", "Name");
	        link_href_Field.setValueXPath("author/name");

	        setFields(title_Field,updated_Field,link_href_Field,published_Field,id_Field,twitter_source_Field,uri_Field,name_Field);
	        setClientOnly(true);

	    }


}

can someone help me on this?

Works now

The problem: xmlns definition. Without it works just fine

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:google="http://base.google.com/ns/1.0" 
xml:lang="en-US" 
xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" 
xmlns:twitter="http://api.twitter.com/">
  <id>tag:search.twitter.com,2005:search/twitter</id>
  <link type="text/html" rel="alternate" href="http://search.twitter.com/search?q=twitter"/>
  <link type="application/atom+xml" rel="self" href="http://search.twitter.com/search.atom?q=twitter"/>
  <title>twitter - Twitter Search</title>
  <link type="application/opensearchdescription+xml" rel="search" href="http://search.twitter.com/opensearch.xml"/>
  <link type="application/atom+xml" rel="refresh" href="http://search.twitter.com/search.atom?q=twitter&since_id=1274320152"/>
  <updated>2009-03-03T16:19:18Z</updated>
  <openSearch:itemsPerPage>15</openSearch:itemsPerPage>
  <link type="application/atom+xml" rel="next" href="http://search.twitter.com/search.atom?max_id=1274320152&page=2&q=twitter"/>
  <entry>
    <id>tag:search.twitter.com,2005:1274320152</id>
    <published>2009-03-03T16:19:18Z</published>
    <link type="text/html" rel="alternate" href="http://twitter.com/kaplanmyrth/statuses/1274320152"/>
    <title>Watching @ev at #TED talking about #Twitter: http://ping.fm/IS0GK</title>
    <content type="html">Watching <a href="http://twitter.com/ev">@ev</a> at <a href="http://search.twitter.com/search?q=%23TED">#TED</a> talking about <a href="http://search.twitter.com/search?q=%23Twitter">#<b>Twitter</b></a>: <a href="http://ping.fm/IS0GK">http://ping.fm/IS0GK</a></content>
    <updated>2009-03-03T16:19:18Z</updated>
    <link type="image/png" rel="image" href="http://s3.amazonaws.com/twitter_production/profile_images/64875999/andyhand_normal.jpg"/>
    <twitter:source><a href="http://www.ping.fm/">Ping.fm</a></twitter:source>
    <author>
      <name>kaplanmyrth (Andy Kaplan-Myrth)</name>
      <uri>http://twitter.com/kaplanmyrth</uri>
    </author>
  </entry>

<...>

</feed>

the code:

        setID(id);
        XmlNamespaces xmlnamespace = new XmlNamespaces();
        // xmlnamespace.addNamespace("xmlns", "http://www.w3.org/2005/Atom"); // PROBLEM

        xmlnamespace.addNamespace("google", "http://base.google.com/ns/1.0");
        xmlnamespace.addNamespace("lang", "en-US");
        xmlnamespace.addNamespace("openSearch", "http://api.twitter.com/");
        xmlnamespace.addNamespace("twitter", "http://api.twitter.com/");

        setXmlNamespaces(xmlnamespace);

        // Selects all entry elements no matter where they are in the document
        setRecordXPath("//entry");

        DataSourceTextField title_Field = new DataSourceTextField("title", "Title");
        DataSourceTextField updated_Field = new DataSourceTextField("updated", "Updated");
        DataSourceTextField published_Field = new DataSourceTextField("published", "Published");
        DataSourceTextField id_Field = new DataSourceTextField("id", "Id");
        // DataSourceTextField twitter_source_Field = new DataSourceTextField("source", "twitter"); OK WORKS

        DataSourceTextField twitter_source_Field = new DataSourceTextField("source", "twitter"); // WORKS TOO
        twitter_source_Field.setValueXPath("twitter:source");

        DataSourceTextField link_href_Field = new DataSourceTextField("href", "Href");
        link_href_Field.setValueXPath("link/@href");

        DataSourceTextField uri_Field = new DataSourceTextField("uri", "uri");
        uri_Field.setValueXPath("author/uri");

        DataSourceTextField name_Field = new DataSourceTextField("name", "Name");
        name_Field.setValueXPath("author/name");

        setFields(title_Field, updated_Field, published_Field, id_Field, twitter_source_Field, link_href_Field, uri_Field, name_Field);

        setDataURL("data/twitter.xml");

        setClientOnly(true);

Read XML with “xmlns” definition, is that a bug in smartgwt?

@thiagohac No, no bug in SmartGWT, like the previous poster, you need a basic background in XML namespaces and XPath. Your XPath has no namespaces and so will not work.

But how to make the code works with the "xmlns=“http://www.w3.org/2005/Atom” " ?

I try:
xmlnamespace.addNamespace(“xmlns”, “http://www.w3.org/2005/Atom”);
but dont work

My posted code works without it

Without the xmlns definition in XML

Bug or not? Solutions?