SaveToXML

135 views
Skip to first unread message

jesdial

unread,
Jan 31, 2007, 1:02:34 PM1/31/07
to Google Data API
Dear friends

Is there any way i can get an XMLDocument using

AtomFeed.SaveToXML(XmlWriter)

I've tried:
AtomFeed calFeed = service.Query(query);
System.IO.MemoryStream mstream = new System.IO.MemoryStream();

//calFeed.SaveToXml(mstream);

System.Xml.XmlWriter writer = new XmlTextWriter(mstream,
System.Text.Encoding.UTF8);
calFeed.SaveToXml(writer);

XmlDocument myDoc = new XmlDocument();
myDoc.Load(mstream);
writer.Close();


but fails in myDoc.Load(mstream) : no root element...

Thank you in advance


Jesús de Diego

Filipe Alves Ferreira

unread,
Jan 31, 2007, 1:25:29 PM1/31/07
to google-he...@googlegroups.com


Hello,
 
I can't do it as well.
Best regards/Filipe


> From: jes...@gmail.com
> To: google-he...@googlegroups.com
> Subject: SaveToXML
> Date: Wed, 31 Jan 2007 18:02:34 +0000

Frank Mantek

unread,
Feb 1, 2007, 5:51:59 AM2/1/07
to google-he...@googlegroups.com
The following code is taken from objectmodelhelper.cs (part of the unittests) and dumps an atomfeed into a file:

 //////////////////////////////////////////////////////////////////////
       /// <summary>dump feeds</summary>
       /// <param name="theOne">the filenam</param>
       //////////////////////////////////////////////////////////////////////
       public static void DumpAtomObject(AtomBase atom, string baseName)
       {
           if (atom != null)
           {
               StreamWriter stream = new StreamWriter(baseName, false, System.Text.Encoding.UTF8);
               XmlTextWriter writer =  new XmlTextWriter(stream);
               writer.Formatting = Formatting.Indented;
               writer.WriteStartDocument(false);
               atom.SaveToXml(writer);
               writer.Flush();
               writer.Close();
               stream.Close();
           }
       }
       /////////////////////////////////////////////////////////////////////////////

You need to start the document yourself - SaveToXml assumes a prepared document, which makes it hence possible to embbed a feed inside something else, if so desired...

Frank Mantek
Google

jesdial

unread,
Feb 18, 2007, 6:56:16 PM2/18/07
to Google Data API
I finally solved the problem.
Here is my solution:

public XmlDocument GeoAgenda(string GoogleAccount, string password)
{

FeedQuery query = new FeedQuery();
CalendarService service = new
Google.GData.Calendar.CalendarService("GeoReferencing");
// Set your credentials:
NetworkCredential nc = new NetworkCredential(GoogleAccount,
password);
service.Credentials = nc;

// Create the query object:
query.Uri = new Uri("http://www.google.com/calendar/feeds/" +
GoogleAccount +"/private/basic");

//CalendarService service = new
CalendarService("CalendarSampleApp");

GDataRequestFactory f =
(GDataRequestFactory)service.RequestFactory;
IWebProxy iProxy = WebRequest.DefaultWebProxy;
WebProxy myProxy = new WebProxy(iProxy.GetProxy(query.Uri));
// potentially, setup credentials on the proxy here
myProxy.Credentials =
System.Net.CredentialCache.DefaultCredentials;
myProxy.UseDefaultCredentials = true;
f.Proxy = myProxy;

// Tell the service to query:
AtomFeed calFeed = service.Query(query);

XmlDocument XmlDoc = new XmlDocument();
Stream meStream = new MemoryStream();
XmlWriter writer = new XmlTextWriter(meStream,
System.Text.Encoding.UTF8);

calFeed.SaveToXml(writer);

writer.Flush();
meStream.Position = 0;

XmlTextReader xmlreader = new XmlTextReader(meStream);

xmlreader.Read();
XmlDoc.LoadXml("<root>" + xmlreader.ReadInnerXml() + "</
root>");
writer.Close();
....
....
....

return XmlDoc;
}

Thank you all

Jesús de Diego

Reply all
Reply to author
Forward
0 new messages