yangchongze00 / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

No way to create Entry without URI #410

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The AtomEntry objects have a SaveToXml Method to save the entry to XML, but I 
can't find a way to create an entry from the XML (at least without saving it to 
a file and using a URI).  

I save the XML in a database, so I needed a way to create an entry from a 
string or stream.  I overloaded the Get() method of the Service class 
(service.cs) so that I could get an atom entry from a string.

Can we add code something like below to add the ability to create an entry 
object from a string?  Seems like it'd be useful to other folks.

   public AtomEntry Get(string entryXML, string uriToUse)
        {
            AtomFeed feed = null;

            if (entryXML == null)
            {
                throw new System.ArgumentNullException("entryXML", "The argument MUST not be null");
            }

            if (uriToUse == null)
            {
                throw new System.ArgumentNullException("uriToUse", "The argument MUST not be null.  Any uri will be fine.");
            }

            byte[] xmlBytes = System.Text.Encoding.UTF8.GetBytes(entryXML);
            System.IO.MemoryStream responseStream = new System.IO.MemoryStream(xmlBytes, 0, xmlBytes.Length);

            if (responseStream != null)
            {
                feed = CreateAndParseFeed(responseStream, new System.Uri(uriToUse));
            }
            return feed.Entries[0];

        }

Original issue reported on code.google.com by edwin.la...@gmail.com on 27 Jul 2010 at 5:41

GoogleCodeExporter commented 8 years ago
Yes, I also wish there is such method.

What I tried now is to perform sync using FeedSync, and will perform all my 
changes like update, delete, rename etc by just posting feed stream.

But create require unique URI that provided by Google Docs server, so I can't 
perform that.

Original comment by v.han...@gmail.com on 25 Aug 2010 at 4:52